﻿using BarcodeDelay.bean;
using BarcodeDelay.FrameDecoder;
using BarcodeDelay.utility;
using JTParcrelHelper.bean;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace BarcodeDelay.business
{
    public class JTDelayHelperNew
    {
        private StreamWriter swb = null;
        FileStream bFile = null;
        public event Action DoneDepAnay;

        public event Action DoneDepCount;
        public event Action DoneHttpResponse;

        public event Action DoneSBResponse;

        public event Action QueryMessageRes;
        ArrayList m_arListDepBarcodes = new ArrayList();
        public Hashtable m_ht_departure_BarCodes = new Hashtable();
        public ArrayList m_arlist_Delayed_BarCodes = new ArrayList();
        ArrayList arListArbitrationBarcodes = new ArrayList();
        public int curRow = 0;
        public int delayOwnSite = 0;

        public int totalExcuteThreadTimes = 0;
        AutoResetEvent myEvent = new AutoResetEvent(false);

        public object objLock = new object();
        private static JTDelayHelperNew instance;
        public static JTDelayHelperNew Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new JTDelayHelperNew();
                }
                return instance;
            }
        }

        private Thread fThreadDep = null;
        public void BeginAnalyThread(ArrayList arListBarCodes, string anayType)
        {
            try
            {
                StoParams.Instance.htBarcodeResMsg.Clear();
                curRow = 0;
                totalExcuteThreadTimes = 0;
                initLog();
                m_arListDepBarcodes.Clear();
                if (fThreadDep != null && (fThreadDep.ThreadState == ThreadState.Running || fThreadDep.ThreadState == ThreadState.Background))
                {
                    fThreadDep.Abort();
                    System.Threading.Thread.Sleep(50);
                }
                if (fThreadDep != null && (fThreadDep.ThreadState == ThreadState.Running || fThreadDep.ThreadState == ThreadState.Background))
                {
                    while (fThreadDep.ThreadState != ThreadState.Aborted)
                    {
                        //当调用Abort方法后，如果thread线程的状态不为Aborted，主线程就一直在这里做循环，直到thread线程的状态变为Aborted为止
                        Thread.Sleep(100);
                    }
                }
                m_arListDepBarcodes = arListBarCodes;
                fThreadDep = new Thread(new ThreadStart(parseDepartureBarcodes));//出港分析 开辟一个新的线程
                fThreadDep.IsBackground = true;
                fThreadDep.Start();

            }
            catch (Exception ex)
            {

            }
        }

        private void initLog()
        {
            try
            {
                string dir = System.Environment.CurrentDirectory;
                /*if(File.Exists(StoParams.Instance.outputDir + "\\延误.txt"))
                {
                    File.Delete(StoParams.Instance.outputDir + "\\延误.txt");
                }*/
                /*bFile = new FileStream(StoParams.Instance.outputDir + "\\延误.txt", FileMode.Append);
                if (swb == null)
                {
                    swb = new StreamWriter(bFile);

                }*/
            }
            catch (Exception ex)
            {

            }

        }
        private ArrayList getcurPageApplyed(JArray waybills,string curSiteToken)
        {
            ArrayList arListAppliedWaybills = new ArrayList();
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/servicequality/arbitration/list?size=100&current=1";
                JObject jObj = new JObject();

                jObj["createNetworkId"] = Convert.ToInt64(StoParams.Instance.register_networkId);
                jObj["countryId"] = "1";
                jObj["dateType"] = 0;
                jObj["startDate"] = System.DateTime.Now.ToShortDateString() + " 23:59:59";
                jObj["endDate"] = System.DateTime.Now.ToShortDateString() + " 23:59:59";
                jObj["firstId"] = "";
                jObj["secondId"] = "";
                jObj["timeout"] = 25000;
                jObj["type"] = 1;
                jObj["waybillNos"] = waybills;

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string resMsg = HttpClient.HttpUtil.Instance.PostCommonByToken(strUrl, postData, "arbitrationMyApply", curSiteToken);
                if (!resMsg.Contains("请求成功"))
                {
                    return arListAppliedWaybills;
                }

                JObject jsonObjRes = (JObject)JsonConvert.DeserializeObject(resMsg);
                JObject jsonObjData = (JObject)jsonObjRes["data"];
                JArray records = (JArray)jsonObjData["records"];

                for (int i = 0; i < records.Count; i++)
                {
                    JObject json = (JObject)records[i];
                    JToken waybillNo = json["waybillNo"];
                    arListAppliedWaybills.Add(waybillNo.ToString());
                }
            }
            catch (Exception ex)
            {

            }
            return arListAppliedWaybills;
        }

        private void handleDelayThread(object arListBarcode)
        {
            try
            {
                //System.Threading.Thread.Sleep(2000);
                ArrayList arListDepResultTmp = new ArrayList();
                string httpRes = "";
                foreach (string strBarCode in (ArrayList)arListBarcode)
                {
                    try
                    {

                        System.Threading.Thread.Sleep(100);
                        StoParams.Instance.curParces++;
                        curRow++;
                        if (curRow % 500 == 0)
                        {
                            StoParams.Instance.resMsg = "暂停1秒，防止请求过高";
                            DoneHttpResponse.Invoke();
                            System.Threading.Thread.Sleep(1000);
                        }
                        if (arListArbitrationBarcodes.Contains(strBarCode) && strBarCode.Length > 1)
                        {
                            lock(StoParams.Instance.obj_htRes)
                            {
                                StoParams.Instance.htBarcodeResMsg[strBarCode] = "已申报";
                                if(StoParams.Instance.htBarcodeResMsg.Count>2000)
                                {
                                    StoParams.Instance.htBarcodeResMsg.Clear();
                                }
                            }
                            
                            //StoParams.Instance.resMsg = strBarCode + "已申报";
                            DoneHttpResponse.Invoke();
                            System.Threading.Thread.Sleep(100);
                            continue;
                        }
                        ResultBean resultBean = new ResultBean();
                        StoParams.Instance.currentBarcode = strBarCode;
                        StoParams.Instance.resMsg = "";
                        string strResponse = "";
                        ArrayList arListAllGXTask = new ArrayList();
                        ArrayList arListRoadMap = getRoadMap(strBarCode, out httpRes, arListAllGXTask);
                        removeFirstAdditonalRoadMap(arListRoadMap);
                        bool isContainLanshouSite = false;
                        string lanshouSite = "";
                        changeRegSite(arListRoadMap, out isContainLanshouSite, out lanshouSite);
                        string curSiteToken = "";
                        if (!isContainLanshouSite)
                        {
                            string orderSource = "";
                           
                            string customerName = "";
                            if (!UtilityHelp.Instance.resetToken(strBarCode, out lanshouSite, out orderSource, out curSiteToken, out customerName))
                            {  
                                if(!MemberInfo.Instance.jmsUser.Contains("5aiweiqi")&&!StoParams.Instance.register_user.Contains("赵彩银"))
                                {
                                    if (lanshouSite != "")
                                    {
                                        StoParams.Instance.resMsg = "" + lanshouSite + " 未授权";
                                    }
                                    else
                                    {
                                        StoParams.Instance.resMsg = "" + "请求失败,请确认token是否过期 ";
                                        StoParams.Instance.httpResmsg = "请求失败,请确认token是否过期 ";
                                    }

                                    DoneHttpResponse.Invoke();
                                    System.Threading.Thread.Sleep(200);
                                    continue;
                                }
                                else
                                {
                                    if(lanshouSite=="")
                                    {
                                        StoParams.Instance.resMsg = "" + "请求失败,请确认token是否过期 ";
                                        StoParams.Instance.httpResmsg = "请求失败,请确认token是否过期 ";
                                        System.Threading.Thread.Sleep(200);
                                        continue;
                                    }
                                }                           
                                
                            }

                        }

                        if("义乌大塘下网点"== lanshouSite&& !MemberInfo.Instance.jmsUser.Contains("5aiweiqi"))
                        {
                            continue;
                        }

                        string assignTme = "";
                        string dispatchSite = "";
                        string dispatchSiteArrival = "";
                        string terminalDepTime = "";
                        ArrayList arListDBOrJB = new ArrayList();
                        if (!httpRes.Contains("成功") && arListRoadMap.Count == 0)
                        {
                            if (httpRes != "")
                            {
                                StoParams.Instance.resMsg = httpRes;
                                StoParams.Instance.httpResmsg = "请求失败,请确认token是否过期 "+ httpRes;
                            }
                            else
                            {
                                StoParams.Instance.resMsg = "请求失败";
                                StoParams.Instance.httpResmsg = "请求失败,请确认token是否过期";
                            }

                            DoneHttpResponse.Invoke();
                            Random rd2 = new Random();
                            int sleepTime2 = rd2.Next(50, 200);
                            System.Threading.Thread.Sleep(sleepTime2);

                            continue;
                        }

                        if (arListRoadMap.Count == 0)
                        {
                            StoParams.Instance.httpResmsg = "请求错误,请确认token是否过期";
                            StoParams.Instance.resMsg = "请求错误";
                            DoneHttpResponse.Invoke();
                            Random rd2 = new Random();
                            int sleepTime2 = rd2.Next(50, 150);
                            //System.Threading.Thread.Sleep(sleepTime2);
                            continue;
                        }

                        StoParams.Instance.httpResmsg = "请求成功";
                        FrameDecoderManager.Instance.lastSendRes = System.DateTime.Now;
                        string shouldAssignTime = "";
                        string sendToDisSite = "";
                        string orderDispatchSite = "";
                        Hashtable htJS = new Hashtable();
                        JTDelayHelper.Instance.isEffiLate(strBarCode, arListRoadMap, out dispatchSite, out dispatchSiteArrival, out terminalDepTime, out assignTme, out shouldAssignTime, out sendToDisSite,out orderDispatchSite, htJS);
                        //if (!JTDelayHelper.Instance.isEffiLate(strBarCode, arListRoadMap, out dispatchSite, out dispatchSiteArrival, out terminalDepTime, out assignTme, out shouldAssignTime, out sendToDisSite))
                        {
                            //StoParams.Instance.resMsg = strBarCode + "无延误";
                            //DoneHttpResponse.Invoke();
                            //continue;
                        }
                        if(orderDispatchSite != ""&& !JTDelayHelper.Instance.isSignSiteRight(orderDispatchSite, arListRoadMap))
                        {
                            resultBean.isSegmentError = true;
                            //continue;

                        }



                        double delayDays = 0;
                        if (assignTme != "" && shouldAssignTime != "")
                        {
                            TimeSpan ts = Convert.ToDateTime(assignTme) - Convert.ToDateTime(shouldAssignTime);
                            delayDays = Math.Ceiling((double)ts.TotalDays);

                        }

                        if (terminalDepTime != "" && dispatchSiteArrival != "")
                        {
                            if (Convert.ToDateTime(terminalDepTime) > Convert.ToDateTime(dispatchSiteArrival))
                            {
                                terminalDepTime = dispatchSiteArrival;
                            }
                        }
                        Hashtable htTaskSiteArrivalMap = new Hashtable();

                        Hashtable htTaskNoDbgBean = new Hashtable();

                        if (isWaybillDelay(strBarCode, resultBean, arListRoadMap, dispatchSite, dispatchSiteArrival, terminalDepTime, 
                            arListDBOrJB, assignTme, shouldAssignTime, htTaskSiteArrivalMap, htTaskNoDbgBean, lanshouSite))
                        {
                            
                            resultBean.delayDays = resultBean.delayDays.Replace("-", "");
                            if (resultBean.delayDays != "" && MathUtility.ImpIsNum(resultBean.delayDays))
                            {
                                resultBean.delayDays = Math.Abs(Convert.ToInt32(resultBean.delayDays)).ToString();
                            }

                            getFinishTime(arListRoadMap, resultBean);
                            if (resultBean.delayDays == "")
                            {
                                if (sendToDisSite != "" && shouldAssignTime != "")
                                {
                                    TimeSpan ts = Convert.ToDateTime(sendToDisSite) - Convert.ToDateTime(shouldAssignTime);
                                    delayDays = Math.Ceiling((double)ts.TotalDays);
                                    resultBean.delayDays = delayDays.ToString();
                                }
                                else
                                {
                                    resultBean.delayDays = delayDays.ToString();
                                }
                            }


                            foreach (string strTask in arListDBOrJB)
                            {
                                string dutySite = resultBean.dutySite;
                                if (resultBean.dutySite.Contains("集散"))
                                {
                                    string prioCenter = "";
                                    if (htJS.ContainsKey(resultBean.dutySite))
                                    {
                                        dutySite = htJS[dutySite].ToString();
                                    }

                                }
                                if (htTaskSiteArrivalMap.ContainsKey(dutySite))
                                {
                                    DbgBean dbgBean = htTaskSiteArrivalMap[dutySite] as DbgBean;
                                    if (dbgBean.firstTaskNo == strTask)
                                    {
                                        resultBean.taskNo = resultBean.taskNo + strTask + ","+ dbgBean.secondTaskNo;
                                        if (Utility.isTimeRight(dbgBean.plannedArrivalTime))
                                        {
                                            resultBean.planArrivalTime = dbgBean.plannedArrivalTime.ToString();
                                            if (resultBean.planArrivalTime.Contains("-"))
                                            {
                                                resultBean.planArrivalTime = resultBean.planArrivalTime.Substring(resultBean.planArrivalTime.IndexOf('-') + 1);
                                            }

                                        }


                                        if(htTaskNoDbgBean.ContainsKey(strTask))
                                        {
                                            DbgBean dbgTaskBean = htTaskNoDbgBean[strTask] as DbgBean;
                                            if (Utility.isTimeRight(dbgTaskBean.plannedArrivalTime) && Utility.isTimeRight(dbgTaskBean.actualArrivalTime))
                                            {
                                                if (dbgTaskBean.actualArrivalTime > dbgTaskBean.plannedArrivalTime)
                                                {
                                                    dbgBean.isTransferDelay = true;
                                                    resultBean.transferDelay = "是";
                                                }
                                            }
                                        }
                                        

                                    }
                                }

                                

                            }

                            //临时去掉过滤网点
                            if (MemberInfo.Instance.filter.Contains(resultBean.dutySite))
                            {
                                if (!MemberInfo.Instance.jmsUser.Contains("5aiweiqi"))
                                {
                                    delayOwnSite++;
                                    DoneHttpResponse();

                                    continue;
                                }
                                    
                            }
                            resultBean.taskNo = resultBean.taskNo.Trim(',');
                            m_ht_departure_BarCodes[strBarCode] = resultBean;
                            arListDepResultTmp.Add(resultBean.wayBillNo + "," + resultBean.errorMsg + "," + resultBean.dutySite);
                            lock (StoParams.Instance.obj_dep)
                            {
                                m_arlist_Delayed_BarCodes.Add(strBarCode);
                            }
                                
                            if(resultBean.delayDays!="")
                            {
                                try
                                {
                                    int dDay = (int)Convert.ToDecimal(resultBean.delayDays);
                                    if (dDay >= 7)
                                    {
                                        resultBean.errorType = "彻底延误";
                                    }
                                }
                                catch(Exception ex)
                                {

                                }
                               
                            }
                            addResult(strBarCode + " " + resultBean.errorMsg + " " + resultBean.dutySite + " " + resultBean.errorType);
                            StoParams.Instance.resMsg = "延误";
                            DoneDepAnay.Invoke();
                            DoneDepCount.Invoke();

                            Random rd2 = new Random();
                            int sleepTime2 = rd2.Next(50, 150);

                     
                            DoneHttpResponse();
                            //Program.m_frmain.SetTextMessage(intProcess, m_arListDepBarcodes.Count, "");
                            continue;

                        }

                        if (!httpRes.Contains("成功") && httpRes.Length > 1)
                        {
                            StoParams.Instance.resMsg = httpRes;
                        }
                        else if (!StoParams.Instance.resMsg.Contains("延误"))
                        {
                            StoParams.Instance.resMsg = httpRes;
                        }
                        DoneHttpResponse();
                        Random rd = new Random();
                        //int sleepTime = rd.Next(50, 150);
                        System.Threading.Thread.Sleep(25);
                    }
                    catch (Exception ex)
                    {

                    }


                }//foreach
                totalExcuteThreadTimes--;
                if (totalExcuteThreadTimes == 0)
                {
                    if(StoParams.Instance.httpResmsg.Contains("成功"))
                    {
                        StoParams.Instance.httpResmsg =  "所有单号执行完成";
                        StoParams.Instance.resMsg = "所有单号执行完成";
                    }
                    else
                    {
                        StoParams.Instance.httpResmsg = StoParams.Instance.httpResmsg + "所有单号执行完成";
                        StoParams.Instance.resMsg = StoParams.Instance.httpResmsg + "所有单号执行完成";
                    }
                    
                    
                    DoneHttpResponse.Invoke();
                    myEvent.Set();
                }
            }
            catch(Exception ex)
            {
                totalExcuteThreadTimes--;
            }
        }

        private void parseDepartureBarcodes()
        {
            try
            {
                int sumQueryTime = 0;
                int avgQueryTime = 2;
                int intProcess = 0;
                string filter = "";

                string outmsg = "";
                

                if(arListArbitrationBarcodes.Count==0)
                {  
                    //临时     
                    //if(!StoParams.Instance.register_site.Contains("禅城"))
                    {
                        arListArbitrationBarcodes = JTDelayHelper.Instance.getArbitrationBarcodes(out outmsg);
                    }           
                    
                }

                if (arListArbitrationBarcodes.Count>0)
                {
                    StoParams.Instance.resMsg = "已申报数据下载成功，开始分析单号";
                }
                else
                {
                    StoParams.Instance.resMsg = "已申报数据下载失败";
                }
                
                DoneSBResponse.Invoke();
                System.Threading.Thread.Sleep(100);
                StoParams.Instance.resMsg = "";

                ThreadPool.SetMinThreads(3, 3);
                ThreadPool.SetMaxThreads(12, 12);
            
                //ThreadPool.QueueUserWorkItem(new WaitCallback(handleZCBeanThread), zcbean);
                foreach (ArrayList arListBarcode in m_arListDepBarcodes)
                {
                    try
                    {
                        totalExcuteThreadTimes++;
                        intProcess++;
                        int curRow = 0;
                        if(totalExcuteThreadTimes>10)
                        {
                            int a = 0;
                        }
                        ThreadPool.QueueUserWorkItem(new WaitCallback(handleDelayThread), arListBarcode);

                        //Program.m_frmain.SetTextMessage(intProcess, m_arListDepBarcodes.Count, "");
                    }
                    catch(Exception ex)
                    {

                    }
                    
                }
                myEvent.WaitOne();
                StoParams.Instance.resMsg = "所有单号执行完成";
                //System.Windows.Forms.MessageBox.Show("所有任务执行完成");

            }
            catch(Exception ex)
            {

            }

        }

        private void changeRegSite(ArrayList arListRoads,out bool isContainLanshouSite,out string lanshouSite)
        {
           
            isContainLanshouSite = false;
            lanshouSite = "";
            try
            {
                foreach (RoadBean roadBean in arListRoads)
                {
                    if (roadBean.status.Contains("已揽"))
                    {
                        if(roadBean.lanshouSite.Length>3)
                        {
                            lanshouSite = roadBean.lanshouSite;
                        }
                        
                        if (roadBean.lanshouSite.Length > 1&& MemberInfo.Instance.htStaMap.ContainsKey(roadBean.lanshouSite))
                        {
                            DateTime dtExpire = Convert.ToDateTime(MemberInfo.Instance.htStaMap[roadBean.lanshouSite.ToString()].ToString()); ;
                            DateTime dtNow = System.DateTime.Now;
                            if(dtNow<= dtExpire)
                            {
                                StoParams.Instance.register_site = roadBean.lanshouSite;
                                isContainLanshouSite = true;
                            }
                          

                        }

                        if (MemberInfo.Instance.jmsUser.Contains("5aiweiqi") || StoParams.Instance.register_user.Contains("赵彩银"))
                        {
                            StoParams.Instance.register_site = roadBean.lanshouSite;
                            isContainLanshouSite = true;
                            return;
                        }





                    }

                    
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void getFinishTime(ArrayList arListRoads,ResultBean resultBean)
        {
            try
            {
                foreach(RoadBean roadBean in arListRoads)
                {
                    if (roadBean.status.Contains("已揽"))
                    {
                        if(roadBean.lanshouSite.Length>1)
                        {
                            resultBean.lanshouSite = roadBean.lanshouSite;
                        }
                        
                        resultBean.lanshouTime = roadBean.scanTime;
                        if (resultBean.lanshouTime.Contains("-"))
                        {
                            resultBean.lanshouTime = resultBean.lanshouTime.Substring(resultBean.lanshouTime.IndexOf('-') + 1);
                            resultBean.lanshouTime = resultBean.lanshouTime.Substring(0,resultBean.lanshouTime.IndexOf(' '));
                        }                       
                    }

                    if (roadBean.scanTypeName.Contains("入库"))
                    {
                        resultBean.parcelStatus = "已入库";
                        resultBean.inWareHouseTime = roadBean.scanTime;
                        if (resultBean.inWareHouseTime.Contains("-"))
                        {
                            resultBean.inWareHouseTime = resultBean.inWareHouseTime.Substring(resultBean.inWareHouseTime.IndexOf('-') + 1, resultBean.inWareHouseTime.IndexOf(' '));
                            resultBean.inWareHouseTime = resultBean.inWareHouseTime.Substring(0, resultBean.inWareHouseTime.IndexOf(' '));
                        }
                    }

                    if (roadBean.status.Contains("已签收"))
                    {
                        resultBean.parcelStatus = "已签收";
                        resultBean.finishTime = roadBean.scanTime;
                        if(resultBean.finishTime.Contains("-"))
                        {
                            resultBean.finishTime = resultBean.finishTime.Substring(resultBean.finishTime.IndexOf('-') + 1, resultBean.finishTime.IndexOf(' '));
                            resultBean.finishTime = resultBean.finishTime.Substring(0, resultBean.finishTime.IndexOf(' '));
                        }
                        break;
                    }
                }
            }
            catch(Exception ex)
            {

            }
        }

        private void addResult(string strBarCode)
        {
            try
            {
                string curDatetime = System.DateTime.Now.ToString();
                if(bFile==null)
                {
                    bFile = new FileStream(StoParams.Instance.outputDir + "\\延误"+ curDatetime + ".txt", FileMode.Append);
                }
                
                if (swb == null)
                {
                    swb = new StreamWriter(bFile);
                    swb.WriteLine(strBarCode);
                    swb.Close();
                    swb = null;
                    bFile.Close();
                    bFile = null;

                }
            }
            catch(Exception ex)
            {

            }
            
        }
        public ArrayList getRoadMap(string barcode, out string msg, ArrayList arListGXTask)
        {
            msg = "";
            ArrayList arListAllRoadmap = new ArrayList();
            arListGXTask = new ArrayList();
            try
            {
                /*string queryUrl = "https://jmsgw.jtexpress.com.cn/servicequality/thirdService/ops/podTrackingList?waybillNos=" + barcode.Trim();
                JObject jObj = new JObject();

                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string res = HttpClient.HttpUtil.Instance.QueryCommon(queryUrl, postData, "GET", "arbitrationApply");*/
                string queryUrl = " https://jmsgw.jtexpress.com.cn/operatingplatform/podTracking/inner/query/keywordList";
                if (StoParams.Instance.isRabbitWin)
                {
                    queryUrl = "https://wdgw.jtexpress.com.cn/ops/wdbutler/podTracking/inner/query/keywordList";
                }
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                //jObj["current"] = 1;
                jObj["trackingTypeEnum"] = "WAYBILL";
                jObj["countryId"] = "1";
                jarry.Add(barcode);
                jObj["keywordList"] = jarry;
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                HttpClient.HttpUtil httpUtil = new HttpClient.HttpUtil();
                //string res = HttpClient.HttpUtil.Instance.PostCommon(queryUrl, postData, "trackingExpress");
                string res = httpUtil.PostCommon(queryUrl, postData, "trackingExpress");

                if (res.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(res);
                    string resMsg = jsonObj["msg"].ToString();
                    msg = resMsg;
                    
                    JArray dataArr = (JArray)jsonObj["data"];
                    if (dataArr != null)
                    {
                        JObject jsonDetails = (JObject)dataArr[0];
                        JArray detailsRecords = (JArray)jsonDetails["details"];
                        arListAllRoadmap = UtilityHelp.Instance.getDetailRoadMap(detailsRecords, arListGXTask);
                    }


                }
                else
                {
                    if (res.Contains("未能解析此远程名称"))
                    {
                        msg = "网络域名不通";
                    }
                    else if (res.Contains("远程服务器返回错误: (405) 不允许的方法"))
                    {
                        msg = "认证过期，请重新登录JMS，设置机器人在线";
                    }
                    else
                    {
                        msg = res;
                    }
                    //
                }


            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("登录"))
                {
                    msg = "请重新登录JMS，并重新授权，设置机器人在线";

                }
            }
            return arListAllRoadmap;
        }

        private void removeFirstAdditonalRoadMap(ArrayList arListRoadMap)
        {
            try
            {
                int lanShouCount = 0;
                int lastLanshouIndex = 0;
                for(int i=0;i< arListRoadMap.Count;i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if(roadBean.scanTypeName.Contains("揽收")&&i<4)
                    {
                        lanShouCount++;
                        lastLanshouIndex = i;
                    }
                }
                if(lastLanshouIndex > 1&& lanShouCount>1)
                {
                    arListRoadMap.RemoveRange(0, lastLanshouIndex);
                }
                else if(lastLanshouIndex>0&& lastLanshouIndex<3)
                {
                    arListRoadMap.RemoveRange(0, lastLanshouIndex);
                }

            }
            catch(Exception ex)
            {

            }

        }

        private bool isWaybillDelay(string strBarCode,ResultBean resultBean,ArrayList arListRoadMap, string dispatchSite,
            string dispatchSiteArrival,string terminalDepTime, ArrayList arListAllGXDBORJBTask,string assignTme,
            string shouldAssignTime,Hashtable htMainTaskSiteArrival,Hashtable htTaskNoDbgBean,string lanshouSite)
        {
            bool res = false;
           
            try
            {
                Hashtable htCondutTime = new Hashtable();

                ArrayList arListAllGXTask = new ArrayList();
                Hashtable htAllTaskCenter = new Hashtable();
                Hashtable htAllTaskTime = new Hashtable();
                Hashtable htAllSiteTime = new Hashtable();
                ArrayList arListAllCenter = new ArrayList();
                ArrayList arListAllSite = new ArrayList();

                Hashtable htJSTaskMap = new Hashtable();


                resultBean.wayBillNo = strBarCode;
                if(arListRoadMap.Count==0)
                {
                    return res;
                }
                bool isCruReturnParcel = false;
                bool isDestChange = false;
                if(isReturnParcel(arListRoadMap, resultBean,out isDestChange, arListAllGXDBORJBTask))
                {
                    resultBean.errorMsg = "退回件";
                    if (!StoParams.Instance.isShowReturn)
                    {
                        return res;
                    }
                    isCruReturnParcel = true;

                }
                /*if(isDestChange)
                {
                    return res;
                }*/
                resultBean.dutySite = "测试";
                ArrayList arListRoanAllCenters = new ArrayList();
                Hashtable htRightTimeSites = new Hashtable();
                Hashtable htCenterFromList = new Hashtable();
                getRoadDbgEachSite(arListRoadMap, arListAllSite, htAllSiteTime, arListAllGXTask, arListRoanAllCenters, htRightTimeSites);
               
                JTDelayHelper.Instance.getAllGXTimeByRoadMap(arListRoadMap, arListAllGXTask, htAllTaskCenter, htAllTaskTime, arListAllCenter,
                    htRightTimeSites, htJSTaskMap, htTaskNoDbgBean, htCenterFromList);
                //JTDelayHelper.Instance.getAllGXTime(arListAllGXTask, htAllTaskCenter, htAllTaskTime, arListAllCenter, htRightTimeSites);
                handleLastCenterArrivalTime(arListRoadMap, arListAllSite, arListRoanAllCenters, htAllSiteTime, htAllTaskTime, htCenterFromList);
                JTDelayHelper.Instance.handleAllGXTime(arListRoadMap, htAllTaskTime);

                foreach(DictionaryEntry de in htAllTaskTime)
                {
                    htMainTaskSiteArrival[de.Key.ToString()] = de.Value;
                }
                //htMainTaskSiteArrival = (Hashtable)htAllTaskTime.Clone();


                if (!JTDelayHelper.Instance.isReallyLateIfUsingTermianlSendTime(arListRoadMap, dispatchSite, shouldAssignTime))
                {
                    return false;
                }

                ArrayList arListDelete = new ArrayList();
                foreach(string centerName in arListRoanAllCenters)
                {
                    if(!arListAllCenter.Contains(centerName))
                    {
                        arListDelete.Add(centerName);
                    }
                }
                foreach(string centerName in arListDelete)
                {
                    arListRoanAllCenters.Remove(centerName);
                }

                ArrayList arListDel = new ArrayList();
                foreach (string centerName in arListAllSite)
                {
                    if(centerName.Contains("转运中心")|| centerName.Contains("分拨"))
                    {
                        if(!arListRoanAllCenters.Contains(centerName))
                        {
                            arListDel.Add(centerName);
                        }
                    }
                    
                }

                foreach(RoadBean roadBin in arListRoadMap)
                {
                    try
                    {
                        if(arListDel.Contains(roadBin.scanNetworkName))
                        {
                            if (roadBin.scanTypeName== "装车发件")
                            {
                                arListDel.Remove(roadBin.scanNetworkName);
                            }
                        }
                        
                    }
                    catch(Exception ex)
                    {

                    }
                   
                }


                foreach(string delCent in arListDel)
                {
                    arListAllSite.Remove(delCent);
                }



                if (isWaybillSortWrong(resultBean, arListRoadMap, arListAllGXTask,dispatchSiteArrival, dispatchSite, arListRoanAllCenters)&&!isDestChange)
                {
                    bool isMachineSortWrong = false;
                    handleDutySiteTranferOutDelay(arListRoadMap, resultBean,out isMachineSortWrong);
                    if(!isMachineSortWrong)
                    {
                        if (resultBean.dutySite.Contains("网点"))
                        {
                            //resultBean.errorType = "错分未及时转出";
                            //resultBean.errorMsg= "错分未及时转出";
                        }
                        else if (resultBean.dutySite.Contains("转运中心") || resultBean.dutySite.Contains("分拨"))
                        {
                            resultBean.errorType = "中转错分、错发";
                            //resultBean.errorMsg = "中转错分、错发";
                        }
                        else if (resultBean.dutySite.Contains("集散"))
                        {
                            resultBean.errorType = "集散错分";
                            //resultBean.errorMsg = "中转错分、错发";
                        }

                        res = true;
                        if (isCruReturnParcel)
                        {
                            res = false;
                        }
                    }
                    else
                    {
                        res = false;
                    }
                    
                }
               

                if(isGXContainSortWrong(htAllTaskCenter, resultBean))
                {
                    res = false;
                }
                getLastOmitRoadDbgEachSite(arListRoadMap, arListAllSite, htAllSiteTime, arListAllGXTask, arListRoanAllCenters);

                /*else if (isTransferLong(resultBean, arListRoadMap))
                {
                    res = true;
                }*/
                if (!res)
                {
                    /*if (isSiteReturnDelay(arListRoadMap, resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }*/

                    if (isSelfReturnDelay(arListRoadMap, resultBean, arListAllSite, htAllSiteTime, 
                        htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival,lanshouSite))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }
                    if (isDispatchSiteDelayTooLong(arListRoadMap, resultBean))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }
                    if (isPickoutNoScanProblemReturnDelay(arListRoadMap, resultBean, arListAllSite,
                        htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival, lanshouSite) && isCruReturnParcel)
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }
                    else if(isPickoutNoScanProblem(arListRoadMap, resultBean, arListAllSite,
                        htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival, lanshouSite))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }
                    

                    

                    if (isCenterOrSiteReturnDelay(arListRoadMap, resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }

                    if (isInterceptSiteArrivalLate(arListRoadMap, resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }

                    
                    if (isTransferArrivalLate(arListRoadMap, resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }


                    if (isInterCeptSiteNoActlLate(arListRoadMap, resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }

                    if (isSiteReturnDelayOnlyBaseInterCeptTime(arListRoadMap, resultBean, htAllTaskTime, htAllSiteTime))
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                        res = true;
                        return res;
                    }



                    if (resultBean.errorMsg.Contains("退回"))
                    {
                        ArrayList arListPart = getReturnPartRoadMap(arListRoadMap);
                        if(isReturnCenterDelay(arListPart, resultBean))
                        {
                            handleProtectLine(resultBean, arListPart, htAllSiteTime, htAllTaskTime);
                            res = true;
                            return res;
                        }

                        return false;
                    }
                    
                    if (isDestChange)
                    {
                        res = false;
                        return res;
                    }
                    /*if(isCruReturnParcel)
                    {
                        return res;
                    }*/
                   
                    handleAllSiteTime(htAllSiteTime, htAllTaskTime);
                    if (resultBean.errorType.Contains("错发"))
                    {
                        handleDutySiteTimeCozSortWrong(htAllSiteTime, htAllTaskTime, resultBean.dutySite);
                    }
                    
                    if (isWaybillSJDelay(resultBean, arListAllSite, htAllSiteTime, dispatchSite, dispatchSiteArrival,htAllTaskTime))
                    {
                        res = true;
                    }
                    else if(isTerminalProblemDelay(resultBean, arListAllSite, htAllSiteTime, dispatchSite, dispatchSiteArrival, htAllTaskTime, arListRoadMap))
                    {
                        res = true;
                    }
                    //转运发集散延误
                    else if (isTerminalCenterDelay(resultBean, arListAllSite, htAllSiteTime, dispatchSite, dispatchSiteArrival, htAllTaskTime, assignTme))
                    {
                        res = true;
                    }
                    //集散发集散延误eg:蒙自集散点 发晓龙岛集散点
                    else if (isJSToJSDelay(resultBean, arListAllSite, htAllSiteTime, dispatchSite, dispatchSiteArrival, htAllTaskTime))
                    {
                        res = true;
                    }
                    //终端集散晚到件
                    else if (isTerminalJSDelayArrival(resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        res = true;
                    }
                    //终端转运晚到件
                    /*else if (isTerminalCenterDelayArrival(resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        res = true;
                    }*/
                    //转运或者集散发网点（非派件网点）延误，
                    else if (isTeminalToMiddleSiteDelay(resultBean, arListAllSite, htAllSiteTime, dispatchSite, dispatchSiteArrival, htAllTaskTime))
                    {
                        res = true;
                    }

                    else if (isTransferCenterDelay(resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival, isCruReturnParcel))
                    {
                        res = true;
                    }
                   
                    else if (isStayInCenterMoreThan1Day(resultBean, arListRoanAllCenters, htAllTaskTime))
                    {
                        res = true;
                    }

                    else if (isStayInSiteMoreThan1Day(resultBean, arListAllSite, htRightTimeSites, htAllTaskTime))
                    {
                        res = true;
                    }
                    else if (isSiteNoActlLate(arListRoadMap, resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        res = true;
                    }
                    else if (isSiteArrivalLate(arListRoadMap, resultBean, arListAllSite, htAllSiteTime, htAllTaskTime, terminalDepTime, arListRoanAllCenters, dispatchSite, dispatchSiteArrival))
                    {
                        res = true;
                    }

                    //if (res&&(resultBean.errorMsg.Contains("晚发")|| resultBean.errorType.Contains("未及时转出")))
                    if (res)
                    {
                        handleProtectLine(resultBean, arListRoadMap, htAllSiteTime, htAllTaskTime);
                    }
                    if(res)
                    {
                        handleLastScanType(arListRoadMap, resultBean);
                        if(htAllTaskTime.Contains(resultBean.dutySite))
                        {
                            //本地路线获取
                            //handleRoadMapTf(resultBean, htAllTaskTime, arListRoadMap);
                            handleRoadMapTfLocal(resultBean, htAllTaskTime, arListRoadMap);
                        }
                        
                        if(resultBean.dutySite.Contains("转运")|| resultBean.dutySite.Contains("分拨"))
                        {
                            if(resultBean.errorType.Contains("中转")|| resultBean.errorType.Contains("末端"))
                            {
                                if(htAllTaskTime.ContainsKey(resultBean.dutySite))
                                {
                                    handlePlanDepTimeCenter(resultBean, htAllTaskTime);
                                }
                            }
                        }

                        if (resultBean.dutySite.Contains("集散"))
                        {
                            if (resultBean.errorType.Contains("中转"))
                            {
                                if (htAllSiteTime.ContainsKey(resultBean.dutySite))
                                {
                                    //handlePlanDepTimeCenter(resultBean, htAllTaskTime);
                                }
                            }
                        }


                        bool isFilter = isFilterSite(resultBean.dutySite);
                        if(isFilter)
                        {   
                            //临时去掉过滤   
                            if(!MemberInfo.Instance.jmsUser.Contains("5aiweiqi"))
                            {
                                res = false;
                            }              
                           
                        }

                    }

                    
           

                }

                if(resultBean.isSegmentError)
                {
                    resultBean.errorMsg = resultBean.errorMsg + "(段码错误)";
                }
                


            }
            catch(Exception ex)
            {

            }
            return res;
        }


        private void handlePlanDepTimeCenter(ResultBean resultBean, Hashtable htAllTaskTime)
        {
            try
            {
                if(htAllTaskTime.ContainsKey(resultBean.dutySite))
                {
                    DbgBean dbgBean = htAllTaskTime[resultBean.dutySite] as DbgBean;
                    if(utility.Utility.isTimeRight(dbgBean.plannedDepartureTime))
                    {                       

                        resultBean.planDepTime = dbgBean.plannedDepartureTime.ToString();
                        if (resultBean.planDepTime.Contains("-"))
                        {
                            resultBean.planDepTime = resultBean.planDepTime.Substring(resultBean.planDepTime.IndexOf('-') + 1);
                        }
                    }
                    else  if(resultBean.shouldLeaveTime!="")
                    {
                        resultBean.planDepTime = resultBean.shouldLeaveTime.ToString();
                        if (resultBean.planDepTime.Contains("-"))
                        {
                            resultBean.planDepTime = resultBean.planDepTime.Substring(resultBean.planDepTime.IndexOf('-') + 1);
                        }
                    }
                    if (utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        resultBean.actDepTime = dbgBean.actualDepartureTime.ToString();
                        if (resultBean.actDepTime.Contains("-"))
                        {
                            resultBean.actDepTime = resultBean.actDepTime.Substring(resultBean.actDepTime.IndexOf('-') + 1);
                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
        }
        private void handleProtectLine(ResultBean resultBean,ArrayList arListRoadMap,Hashtable htAllSiteTime,Hashtable htAllTaskTime)
        {
            try
            {
                ArrayList arListDelayDates = new ArrayList();
                string msg = "";
                if (JTDelayHelper.Instance.isDeferNetwork(resultBean.wayBillNo, out msg, "", resultBean.dutySite, arListDelayDates))
                {
                    bool isInDefTime = false;
                    isDelayAfterAddDelay(arListRoadMap, resultBean, arListDelayDates, htAllSiteTime, htAllTaskTime, out isInDefTime);
                    if (isInDefTime)
                    {
                        foreach (DelaySiteBean delayBean in arListDelayDates)
                        {
                            resultBean.exceptionReportTime = resultBean.exceptionReportTime + delayBean.starTime + "-" + delayBean.endTime + " 顺延天数:" + delayBean.delayDays.ToString() + ";";
                        }
                    }


                }
            }
            catch(Exception ex)
            {

            }
            
        }

        public bool isFilterSite(string dutySit)
        {
            bool res = false;
            try
            {
                if(MemberInfo.Instance.htFilterMap.ContainsKey(StoParams.Instance.register_site))
                {
                    string filterSites = MemberInfo.Instance.htFilterMap[StoParams.Instance.register_site] as string;
                    if(filterSites.Contains(dutySit))
                    {
                        res = true;
                    }
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }



        private void handleRoadMapTfLocal(ResultBean resultBean, Hashtable htTaskTime, ArrayList arListRoadMap)
        {
            try
            {
                DbgBean dbgBean = htTaskTime[resultBean.dutySite] as DbgBean;
                string taskNo = dbgBean.firstTaskNo;
                if (taskNo == "")
                {
                    return;
                }

                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/pod/getTaskInfo?taskCode=" + taskNo.ToString();
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string response = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "trackingExpress");

                ArrayList arListNetWorks = new ArrayList();
                bool findRoadMap = false;
                if (response.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                    string resMsg = jsonObj["msg"].ToString();
                    JObject dataObj = (JObject)jsonObj["data"];
                    JToken shipmentName = dataObj["shipmentName"];
                    if (shipmentName != null && shipmentName.ToString().Length > 1)
                    {
                        




                    }





                }

                if (!findRoadMap)
                {
                    int i = 0;
                    foreach (RoadBean roadBean in arListRoadMap)
                    {
                        i++;
                        string scanTypeName = roadBean.scanTypeName;
                        if (scanTypeName.Contains("发件") && roadBean.dkgx == taskNo)
                        {
                            string fromCenter = roadBean.scanNetworkName;
                            string toCenter = roadBean.nextStopName;
                            string nextStpCode = "";
                            for (int j = i; j < arListRoadMap.Count; j++)
                            {
                                RoadBean cruroadBean = (RoadBean)arListRoadMap[j];
                                if (cruroadBean.scanNetworkName == toCenter)
                                {
                                    nextStpCode = cruroadBean.scanNetworkCode;
                                    break;
                                }
                            }
                            if ((fromCenter.Contains("转运") || fromCenter.Contains("分拨")) &&
                                (toCenter.Contains("转运") || toCenter.Contains("分拨")))
                            {
                                string planDepTime = roadBean.plannedDepTime;
                                isProcetByDepTimeLocalMap(planDepTime, fromCenter, toCenter, roadBean.scanNetworkCode, nextStpCode, resultBean);
                                break;



                            }
                        }
                    }
                }



            }
            catch (Exception ex)
            {

            }
        }

        private void handleRoadMapTf( ResultBean resultBean,Hashtable htTaskTime,ArrayList arListRoadMap)
        {
            try
            {
                DbgBean dbgBean = htTaskTime[resultBean.dutySite] as DbgBean;
                string taskNo = dbgBean.firstTaskNo;
                if(taskNo=="")
                {
                    return;
                }

                string strUrl = "https://jmsgw.jtexpress.com.cn/operatingplatform/pod/getTaskInfo?taskCode=" + taskNo.ToString();
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string response = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "trackingExpress");

                ArrayList arListNetWorks = new ArrayList();
                bool findRoadMap = false;
                if (response.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                    string resMsg = jsonObj["msg"].ToString();
                    JObject dataObj = (JObject)jsonObj["data"];
                    JToken shipmentName = dataObj["shipmentName"];
                    if(shipmentName!=null&& shipmentName.ToString().Length>1)
                    {
                        strUrl = "https://jmsgw.jtexpress.com.cn/transportation/tmsVehicleLine/listByLineName";
                        jObj = new JObject();
                        jObj["name"] = shipmentName.ToString();
                        jObj["countryId"] = "1";
                        postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);

                        resMsg = HttpClient.HttpUtil.Instance.PostCommon(strUrl, postData, "lineMainNew|transportPlatformIndex");
                        jsonObj = (JObject)JsonConvert.DeserializeObject(resMsg);
                        JArray dataObjArr = (JArray)jsonObj["data"];
                        for(int i=0;i< dataObjArr.Count;i++)
                        {
                            JObject jObjData = (JObject)dataObjArr[i];
                            JToken name = jObjData["name"];
                            JToken endName= jObjData["endName"];

                            JToken planArrivalTime = jObjData["plannedArrivalTime"];
                            if (name.ToString()!= shipmentName.ToString())
                            {
                                continue;
                            }
                            if(htTaskTime.ContainsKey(endName.ToString()))
                            {
                                findRoadMap = true;
                                DbgBean dbg = htTaskTime[endName.ToString()] as DbgBean;
                                if(Utility.isTimeRight(dbg.plannedArrivalTime))
                                {
                                    DateTime dt = dbg.plannedArrivalTime;
                                    DateTime dtPlan = Convert.ToDateTime(planArrivalTime.ToString());
                                    if(dt.Hour== dtPlan.Hour&& dt.Minute== dtPlan.Minute)
                                    {
                                        JToken sendCollect = jObjData["sendCollect"];
                                        if (sendCollect.ToString() == "1")
                                        {
                                            resultBean.jtyf = "是";
                                        }
                                        else if (sendCollect.ToString() == "2")
                                        {
                                            resultBean.jtyf = "否";
                                        }
                                        JToken operateTime = jObjData["operateTime"];
                                        resultBean.operatorTime = operateTime.ToString();

                                        resultBean.operatorTime = UtilityHelp.Instance.getHourMinuteTime(operateTime.ToString());
                                    }
                                }
                            }
                           




                        }




                    }





                }

                if(!findRoadMap)
                {
                    int i = 0;
                    foreach(RoadBean roadBean in arListRoadMap)
                    {
                        i++;
                        string scanTypeName = roadBean.scanTypeName;
                        if(scanTypeName.Contains("发件")&& roadBean.dkgx== taskNo)
                        {
                            string fromCenter = roadBean.scanNetworkName;
                            string toCenter = roadBean.nextStopName;
                            string nextStpCode = "";
                            for(int j=i;j< arListRoadMap.Count;j++)
                            {
                                RoadBean cruroadBean = (RoadBean)arListRoadMap[j];
                                if(cruroadBean.scanNetworkName== toCenter)
                                {
                                    nextStpCode = cruroadBean.scanNetworkCode;
                                    break;
                                }
                            }
                            if((fromCenter.Contains("转运")|| fromCenter.Contains("分拨"))&&
                                (toCenter.Contains("转运") || toCenter.Contains("分拨")))
                            {
                                string planDepTime = roadBean.plannedDepTime;
                                isProcetByDepTime(planDepTime, fromCenter, toCenter, roadBean.scanNetworkCode, nextStpCode, resultBean);
                                break;
                                


                            }
                        }
                    }
                }



            }
            catch (Exception ex)
            {

            }
        }







        private bool isProcetByDepTimeLocalMap(string depTime, string fromCenter, string toCenter, string fromCenterCode, string toCenterCode, ResultBean resultBean)
        {
            bool res = false;
            try
            {
                string key = fromCenter + "-" + toCenter;
                if(LoadBasicHelper.Instance.m_ht_main_line.ContainsKey(key))
                {
                    ArrayList arListMainLineBeans = LoadBasicHelper.Instance.m_ht_main_line[key] as ArrayList;
                    for (int i = 0; i < arListMainLineBeans.Count; i++)
                    {
                        MainLineTimeBean mainbLineBean= (MainLineTimeBean)arListMainLineBeans[i];
                 
                        if (Utility.isTimeRight(Convert.ToDateTime(mainbLineBean.plannedDepartureTime)))
                        {
                            DateTime dt = Convert.ToDateTime(depTime);
                            DateTime dtPlan = Convert.ToDateTime(mainbLineBean.plannedDepartureTime.ToString());
                            if (dt.Hour == dtPlan.Hour && dt.Minute == dtPlan.Minute)
                            {
                                resultBean.jtyf = mainbLineBean.jfyt;
                               
                                resultBean.operatorTime = mainbLineBean.operationHour.ToString();

                                resultBean.operatorTime = UtilityHelp.Instance.getHourMinuteTime(mainbLineBean.operationHour.ToString());
                            }
                        }




                    }
                }

                



            }
            catch (Exception ex)
            {

            }
            return res;

        }


        private bool isProcetByDepTime(string depTime,string fromCenter,string toCenter,string fromCenterCode, string toCenterCode, ResultBean resultBean)
        {
            bool res = false;
            try
            {
                string strUrl = "https://jmsgw.jtexpress.com.cn/transportation/tmsVehicleLine/page?current=1&size=20&startVeidoo=2&timeType=1&isEnables=1&startName=" + fromCenter.ToString()+ "&startCode="+ fromCenterCode+ "&endName=" + toCenter+ "&endCode="+ toCenterCode;
                JObject jObj = new JObject();
                JArray jarry = new JArray();
                string postData = Newtonsoft.Json.JsonConvert.SerializeObject(jObj);
                string response = HttpClient.HttpUtil.Instance.QueryCommon(strUrl, postData, "GET", "lineMainNew|transportPlatformIndex");

                ArrayList arListNetWorks = new ArrayList();
                bool findRoadMap = false;
                if (response.Contains("data"))
                {
                    JObject jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                    string resMsg = jsonObj["msg"].ToString();
                    JObject dataObj = (JObject)jsonObj["data"];
                    JToken shipmentName = dataObj["shipmentName"];
                    jsonObj = (JObject)JsonConvert.DeserializeObject(response);
                    JObject dataObj2 = (JObject)jsonObj["data"];
                    JArray dataObjArr = (JArray)dataObj2["records"];

                    for (int i = 0; i < dataObjArr.Count; i++)
                    {
                        JObject jObjData = (JObject)dataObjArr[i];
                        JToken name = jObjData["name"];
                        JToken endName = jObjData["endName"];

                        JToken plannedDepartureTime = jObjData["plannedDepartureTime"];
                        if (Utility.isTimeRight(Convert.ToDateTime(depTime)))
                        {
                            DateTime dt = Convert.ToDateTime(depTime);
                            DateTime dtPlan = Convert.ToDateTime(plannedDepartureTime.ToString());
                            if (dt.Hour == dtPlan.Hour && dt.Minute == dtPlan.Minute)
                            {
                                JToken sendCollect = jObjData["sendCollect"];
                                if (sendCollect.ToString() == "1")
                                {
                                    resultBean.jtyf = "是";
                                }
                                else if (sendCollect.ToString() == "2")
                                {
                                    resultBean.jtyf = "否";
                                }
                                JToken operateTime = jObjData["operateTime"];
                                resultBean.operatorTime = operateTime.ToString();

                                resultBean.operatorTime = UtilityHelp.Instance.getHourMinuteTime(operateTime.ToString());
                            }
                        }




                    }






                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }

        private void handleLastScanType(ArrayList arListRoadMap, ResultBean resultBean)
        {
            try
            {
                for(int i= arListRoadMap.Count-1; i>0;i--)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if(roadBean.scanNetworkName!=StoParams.Instance.register_site)
                    {
                        if(roadBean.scanNetworkName.Contains("网点"))
                        {
                            resultBean.assignSite = roadBean.scanNetworkName;
                        }
                        resultBean.lastScanType = roadBean.scanTypeName;
                        resultBean.lastScanTime = roadBean.scanTime;
                        if(resultBean.lastScanTime.Contains("-"))
                        {
                            resultBean.lastScanTime = resultBean.lastScanTime.Substring(resultBean.lastScanTime.IndexOf('-') + 1);
                        }
                        break;
                    }
                }

            }
            catch(Exception ex)
            {

            }
        }

        private bool isDelayAfterAddDelay(ArrayList arListRoadMap,ResultBean resultBean,ArrayList arListDelays,Hashtable htAllSiteTime,Hashtable htAllTaskTime, out bool isInDefTime)
        {
            bool res = true;
            isInDefTime = false;
            try
            {
                DateTime arrivalTime = System.DateTime.Now;
                DateTime dtPlanDepTime = System.DateTime.Now.AddDays(-10);
                if (htAllTaskTime.ContainsKey(resultBean.dutySite))
                {
                    DbgBean dbgBean = (DbgBean)htAllTaskTime[resultBean.dutySite];
                    arrivalTime = dbgBean.plannedArrivalTime;
                    if(utility.Utility.isTimeRight(dbgBean.plannedDepartureTime))
                    {
                        dtPlanDepTime = dbgBean.plannedDepartureTime;
                    }
                    else
                    {
                        dtPlanDepTime = dbgBean.actualDepartureTime;
                    }
                    
                }
                else if (htAllSiteTime.ContainsKey(resultBean.dutySite))
                {
                    DbgBean dbgBean = (DbgBean)htAllSiteTime[resultBean.dutySite];
                    arrivalTime = dbgBean.actualArrivalTime;
                    dtPlanDepTime = dbgBean.actualDepartureTime;
                    if (!utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                    {
                        foreach(RoadBean road in arListRoadMap)
                        {
                            if(road.nextStopName== resultBean.dutySite)
                            {
                                arrivalTime = Convert.ToDateTime(road.scanTime);
                                break;
                            }
                        }
                    }
                }
                int delayDays = 0;
                foreach (DelaySiteBean delaySiteBean in arListDelays)
                {
                    if (arrivalTime > delaySiteBean.starTime && arrivalTime < delaySiteBean.endTime)
                    {
                        isInDefTime = true;
                        delayDays = delaySiteBean.delayDays;
                        break;
                    }
                }
                if(!isInDefTime)
                {
                    foreach (DelaySiteBean delaySiteBean in arListDelays)
                    {
                        if (arrivalTime > delaySiteBean.starTime.AddDays(-2) && arrivalTime < delaySiteBean.endTime.AddDays(1))
                        {
                            isInDefTime = true;
                            delayDays = delaySiteBean.delayDays;
                            break;
                        }
                    }
                }
                if(resultBean.shouldLeaveTime!="")
                {
                    if (dtPlanDepTime < Convert.ToDateTime(resultBean.shouldLeaveTime).AddDays(delayDays))
                    {
                        res = false;
                    }
                }
                
            }
            catch(Exception ex)
            {
                res = false;
            }
            return res;



        }

        private bool isTeminalToMiddleSiteDelay(ResultBean resultBean, ArrayList arListAllSite, Hashtable htAllSiteTime, string dispatchSite, string dispatchSiteArrival, Hashtable htAllTaskTime)
        {
            bool res = false;
            try
            {
                string middleTerminalSite = "";
                string lastCenter = "";
                if (!arListAllSite.Contains(dispatchSite))
                {
                    return res;
                }
                int indexDispatchSite = arListAllSite.IndexOf(dispatchSite);
                int middleSiteIndex = indexDispatchSite - 1;
                middleTerminalSite = arListAllSite[middleSiteIndex].ToString();
                string jsDepTime = "";
                string jsArrivalTime = "";
                string assignTime = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";
                string lastCenterPlanDepTime = "";
                string jsActDepTime = "";
                string centerActDepToJS = "";
                string middleSiteArrivalTime = "";
                string middleSiteDepTime = "";


                lastCenter = arListAllSite[middleSiteIndex - 1].ToString();

                if (!lastCenter.Contains("中心"))
                {
                    return res;
                }
      

                if (middleTerminalSite == lastCenter)
                {
                    middleTerminalSite = dispatchSite;
                }
                if (!middleTerminalSite.Contains("集散")&& !middleTerminalSite.Contains("网点"))
                {
                    return false;
                }

                if (htAllTaskTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgBean = htAllTaskTime[lastCenter] as DbgBean;
                    if (utility.Utility.isTimeRight(dbgBean.plannedArrivalTime))
                    {
                        lastCenterPlanArriveTime = dbgBean.plannedArrivalTime.ToString();
                    }
                    if (utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                    {
                        lastCenterActArriveTime = dbgBean.actualArrivalTime.ToString();
                    }
                }


                if (htAllSiteTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgBean = htAllSiteTime[lastCenter] as DbgBean;

                    if (utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        centerActDepToJS = dbgBean.actualDepartureTime.ToString();
                    }

                }


                if (htAllSiteTime.ContainsKey(middleTerminalSite))
                {
                    DbgBean dbgBean = htAllSiteTime[middleTerminalSite] as DbgBean;

                    if (utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                    {
                        middleSiteArrivalTime = dbgBean.actualArrivalTime.ToString();
                    }
                    if (utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        middleSiteDepTime = dbgBean.actualDepartureTime.ToString();
                    }
                }




                string concuteDateTime = lastCenterPlanArriveTime;
                if (lastCenterPlanArriveTime != "" && lastCenterActArriveTime != "")
                {
                    if (Convert.ToDateTime(lastCenterActArriveTime) > Convert.ToDateTime(lastCenterPlanArriveTime))
                    {
                        concuteDateTime = lastCenterActArriveTime;
                    }
                }

                double addTime = 1;
                if (StoParams.Instance.isUseOperationTime)
                {
                    int rowIndex = arListAllSite.IndexOf(lastCenter);
                    if (rowIndex > 1)
                    {
                        string priorCenter = arListAllSite[rowIndex - 1].ToString();
                        addTime = UtilityHelp.Instance.getArrivaCenterAddHour(priorCenter, lastCenter, concuteDateTime);

                    }
                    else
                    {
                        addTime = 0;
                    }
                }
                //concuteDateTime = Convert.ToDateTime(concuteDateTime).AddHours(addTime).ToString();
                string planArrivalNextSiteTime = "";

                //转运发集散是否延误
                if (UtilityHelp.Instance.isTerminalSendNextLate(resultBean, concuteDateTime, lastCenterActArriveTime, centerActDepToJS, arListAllSite, htAllSiteTime, lastCenter, middleTerminalSite, out planArrivalNextSiteTime, dispatchSiteArrival))
                {
                    return true;
                }











            }
            catch (Exception ex)
            {

            }
            return res;
        }

        private void handleAllSiteTime(Hashtable htAllSiteTime,Hashtable htAllTaskTime)
        {
            try
            {
                foreach( string  key in htAllTaskTime.Keys)
                {
                    if(htAllSiteTime.ContainsKey(key))
                    {
                        DbgBean dbgTaskBean = htAllTaskTime[key] as DbgBean;
                        DbgBean dbgSiteBean = htAllSiteTime[key] as DbgBean;
                        if(utility.Utility.isTimeRight(dbgTaskBean.actualDepartureTime)&&!utility.Utility.isTimeRight(dbgSiteBean.actualDepartureTime))
                        {
                            dbgSiteBean.actualDepartureTime = dbgTaskBean.actualDepartureTime;
                        }
                        if (utility.Utility.isTimeRight(dbgTaskBean.actualArrivalTime) && !utility.Utility.isTimeRight(dbgSiteBean.actualArrivalTime))
                        {
                            dbgSiteBean.actualArrivalTime = dbgTaskBean.actualArrivalTime;
                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
        }


        private void handleDutySiteTimeCozSortWrong(Hashtable htAllSiteTime, Hashtable htAllTaskTime,string dutySite)
        {
            try
            {
                if(htAllSiteTime.ContainsKey(dutySite))
                {
                    DbgBean dbgTaskBean = htAllSiteTime[dutySite] as DbgBean;
                    if(dbgTaskBean.arListDepTimes.Count>1)
                    {
                        dbgTaskBean.actualDepartureTime = Convert.ToDateTime(dbgTaskBean.arListDepTimes[0]);
                        dbgTaskBean.actualArrivalTime = dbgTaskBean.firstArrival;
                    }
                }
             
            }
            catch (Exception ex)
            {

            }
        }


        private bool isTerminalJSDelayArrival(ResultBean resultBean, ArrayList arListAllSite, Hashtable htAllSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListRoanAllCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            try
            {
                int lastJSIndex = arListAllSite.Count - 1;
                if(arListAllSite[lastJSIndex].ToString().Contains("网点"))
                {
                    lastJSIndex = lastJSIndex - 1;
                }
                string lastJS = arListAllSite[lastJSIndex].ToString();
                string priorTermianl = arListAllSite[lastJSIndex-1].ToString();
                DateTime dtLastCenterPlanArrival = new DateTime();
                DateTime dtLastCenterActArrival = new DateTime();

                DateTime dtLastCenterScanArrival = new DateTime();
                DateTime dtLastCenterScanDep = new DateTime();

                if(!lastJS.Contains("集散")||! priorTermianl.Contains("转运"))
                {
                    return res;
                }

                ArrayList arListEffi = new ArrayList();
                if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(priorTermianl))
                {
                    Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[priorTermianl] as Hashtable;
                    if (ht.ContainsKey(lastJS))
                    {
                        arListEffi = ht[lastJS] as ArrayList;
                    }
                    else
                    {
                        string tmpJS = lastJS.Replace("市", "");
                        if (ht.ContainsKey(tmpJS))
                        {
                            arListEffi = ht[tmpJS] as ArrayList;
                        }

                    }
                }

                DbgBean dbgCur = htAllSiteTime[priorTermianl] as DbgBean;
                string latestTime = "";
                if (arListEffi.Count > 0)
                {
                    latestTime = UtilityHelp.Instance.getLastDispatchSiteArrival(arListEffi, dbgCur.actualArrivalTime.ToString());
                }
                else
                {
                    latestTime = "12:00";
                }
                if (latestTime != "" && utility.Utility.isTimeRight(dtLastCenterPlanArrival) &&
                    utility.Utility.isTimeRight(dtLastCenterActArrival) &&
                    utility.Utility.isTimeRight(dtLastCenterScanArrival) &&
                    utility.Utility.isTimeRight(dtLastCenterScanDep))
                {
                    if (dtLastCenterPlanArrival < dtLastCenterActArrival)
                    {
                        dtLastCenterPlanArrival = dtLastCenterActArrival;
                    }
                    string planArriTime = dtLastCenterPlanArrival.ToString().Substring(dtLastCenterPlanArrival.ToString().IndexOf(' ') + 1);

                    string actArriTime = dtLastCenterScanArrival.ToString().Substring(dtLastCenterScanArrival.ToString().IndexOf(' ') + 1);
                    int addDays = 0;
                    if (Convert.ToDateTime(latestTime) < Convert.ToDateTime(planArriTime))
                    {
                        addDays = 1;
                    }
                    string tmpDate = dtLastCenterPlanArrival.AddDays(addDays).ToString();
                    latestTime = tmpDate.Substring(0, tmpDate.IndexOf(' ')) + latestTime;
                    if (dtLastCenterPlanArrival <= Convert.ToDateTime(latestTime) &&
                        dtLastCenterScanArrival > Convert.ToDateTime(latestTime))
                    {
                        resultBean.errorType = "末端到件延误";
                        //resultBean.errorMsg = lastCenter + "末端到件延误";
                        //dutySite = lastCenter;
                        res = true;
                    }


                }

            }
            catch (Exception ex)
            {

            }
            return res;

        }
        private bool isTerminalCenterDelayArrival(ResultBean resultBean, ArrayList arListAllSite, Hashtable htAllSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListRoanAllCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            try
            {
                string lastCenter = arListRoanAllCenters[arListRoanAllCenters.Count - 1].ToString();
                DateTime dtLastCenterPlanArrival=new DateTime();
                DateTime dtLastCenterActArrival = new DateTime();


             


                DateTime dtLastCenterScanArrival = new DateTime();
                DateTime dtLastCenterScanDep = new DateTime();
                if (htAllTaskTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgLast = htAllTaskTime[lastCenter] as DbgBean;
                    //2023-03-20 修改为plannedArrivalTime，对应单号 JT3026979411590
                    //dtLastCenterPlanArrival = dbgLast.lastPlannedArrival;
                    dtLastCenterPlanArrival = dbgLast.plannedArrivalTime;
                    dtLastCenterActArrival = dbgLast.actualArrivalTime;
                }

                if (htAllSiteTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgLast = htAllSiteTime[lastCenter] as DbgBean;
                    dtLastCenterScanArrival = dbgLast.actualArrivalTime;
                    dtLastCenterScanDep = dbgLast.actualDepartureTime;
                }

                string nextSite = arListAllSite[arListAllSite.LastIndexOf(lastCenter) + 1].ToString();
                ArrayList arListEffi = new ArrayList();
                if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lastCenter))
                {
                    Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[lastCenter] as Hashtable;
                    if(ht.ContainsKey(nextSite))
                    {
                        arListEffi = ht[nextSite] as ArrayList;
                    }
                }
                string latestTime = "";
                if(arListEffi.Count>0)
                {
                    latestTime = UtilityHelp.Instance.getLastDispatchSiteArrival(arListEffi, dtLastCenterPlanArrival.ToString());
                }
                else
                {
                    latestTime = "12:00";
                }
                if(latestTime!=""&&utility.Utility.isTimeRight(dtLastCenterPlanArrival)&& 
                    utility.Utility.isTimeRight(dtLastCenterActArrival)&&
                    utility.Utility.isTimeRight(dtLastCenterScanArrival)&&
                    utility.Utility.isTimeRight(dtLastCenterScanDep))
                {
                    if(dtLastCenterPlanArrival< dtLastCenterActArrival)
                    {
                        dtLastCenterPlanArrival = dtLastCenterActArrival;
                    }
                    string planArriTime = dtLastCenterPlanArrival.ToString().Substring(dtLastCenterPlanArrival.ToString().IndexOf(' ') + 1);

                    string actArriTime = dtLastCenterScanArrival.ToString().Substring(dtLastCenterScanArrival.ToString().IndexOf(' ') + 1);
                    int addDays = 0;
                    if(Convert.ToDateTime(latestTime)<Convert.ToDateTime(planArriTime))
                    {
                        addDays = 1;
                    }
                    string tmpDate = dtLastCenterPlanArrival.AddDays(addDays).ToString();
                    latestTime = tmpDate.Substring(0,tmpDate.IndexOf(' '))+" "+ latestTime;
                    /*if (dtLastCenterPlanArrival <= Convert.ToDateTime(latestTime)&&
                        dtLastCenterScanArrival > Convert.ToDateTime(latestTime))*/
                    if(addDays>0)
                    {
                        resultBean.errorType = "末端到件延误";
                        resultBean.errorMsg= lastCenter+"末端到件延误";
                        resultBean.dutySite = lastCenter;
                        res = true;
                    }

                    if(res)
                    {
                        if(dtLastCenterPlanArrival.ToShortDateString()==Convert.ToDateTime(dispatchSiteArrival).ToShortDateString())
                        {
                            res = false;
                        }
                    }


                }

            }
            catch(Exception ex)
            {

            }
            return res;
                
        }

        private bool isJSToJSDelay(ResultBean resultBean, ArrayList arListAllSite, Hashtable htAllSiteTime, string dispatchSite, string dispatchSiteArrival, Hashtable htAllTaskTime)
        {
            bool res = false;
            try
            {
                string jsSite = "";
                string lastCenter = "";
                if (!arListAllSite.Contains(dispatchSite))
                {
                    return res;
                }
                int indexDispatchSite = arListAllSite.IndexOf(dispatchSite);
                int jsSiteIndex = indexDispatchSite - 1;
                jsSite = arListAllSite[jsSiteIndex].ToString();
                string jsDepTime = "";
                string jsArrivalTime = "";
                string assignTime = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";
                string lastCenterPlanDepTime = "";
                string jsActDepTime = "";
                string centerActDepToJS = "";
                string priorJSArrivalTime = "";
                string priorJSDepTime = "";

             


                string priorJS = arListAllSite[jsSiteIndex - 1].ToString();
                lastCenter= arListAllSite[jsSiteIndex - 2].ToString();

                if(!lastCenter.Contains("中心")|| !priorJS.Contains("集散")|| !jsSite.Contains("集散"))
                {
                    return res;
                }
                if(priorJS== jsSite)
                {
                    return res;
                }
                
                if (jsSite == lastCenter)
                {
                    jsSite = dispatchSite;
                }
                if (!jsSite.Contains("集散"))
                {
                    return false;
                }

                if (htAllTaskTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgBean = htAllTaskTime[lastCenter] as DbgBean;
                    if (utility.Utility.isTimeRight(dbgBean.plannedArrivalTime))
                    {
                        lastCenterPlanArriveTime = dbgBean.plannedArrivalTime.ToString();
                    }
                    if (utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                    {
                        lastCenterActArriveTime = dbgBean.actualArrivalTime.ToString();
                    }
                }


                if(htAllSiteTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgBean = htAllSiteTime[lastCenter] as DbgBean;
                    
                    if (utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        centerActDepToJS = dbgBean.actualDepartureTime.ToString();
                    }
                    
                }


                if (htAllSiteTime.ContainsKey(priorJS))
                {
                    DbgBean dbgBean = htAllSiteTime[priorJS] as DbgBean;

                    if (utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                    {
                        priorJSArrivalTime = dbgBean.actualArrivalTime.ToString();
                    }
                    if (utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        priorJSDepTime = dbgBean.actualDepartureTime.ToString();
                    }                    
                }

                if (htAllSiteTime.ContainsKey(jsSite))
                {
                    DbgBean dbgBean = htAllSiteTime[jsSite] as DbgBean;

                    if (utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                    {
                        jsArrivalTime = dbgBean.actualArrivalTime.ToString();
                    }
                    if (utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        jsDepTime = dbgBean.actualDepartureTime.ToString();
                    }
                }
                

                string concuteDateTime = lastCenterPlanArriveTime;
                if (lastCenterPlanArriveTime != "" && lastCenterActArriveTime != "")
                {
                    if (Convert.ToDateTime(lastCenterActArriveTime) > Convert.ToDateTime(lastCenterPlanArriveTime))
                    {
                        concuteDateTime = lastCenterActArriveTime;
                    }
                }

                double addTime = 1;
                if (StoParams.Instance.isUseOperationTime)
                {
                    int rowIndex = arListAllSite.IndexOf(lastCenter);
                    if (rowIndex > 1)
                    {
                        string priorCenter = arListAllSite[rowIndex - 1].ToString();
                        addTime = UtilityHelp.Instance.getArrivaCenterAddHour(priorCenter, lastCenter, concuteDateTime);

                    }
                    else
                    {
                        addTime = 0;
                    }
                }
                //concuteDateTime = Convert.ToDateTime(concuteDateTime).AddHours(addTime).ToString();
                string planArrivalNextSiteTime = "";

                //转运发集散是否延误
                if(UtilityHelp.Instance.isTerminalSendNextLate(resultBean, concuteDateTime, lastCenterActArriveTime, centerActDepToJS, arListAllSite, htAllSiteTime, lastCenter, priorJS,out planArrivalNextSiteTime, dispatchSiteArrival))
                {
                    return true;
                }

                string planNextJSTime = "";
                //集散发集散是否延误
                if (UtilityHelp.Instance.isTerminalSendNextLate(resultBean, planArrivalNextSiteTime, priorJSArrivalTime, priorJSDepTime, arListAllSite, htAllSiteTime, priorJS, jsSite,out planNextJSTime, dispatchSiteArrival))
                {
                    return true;
                }

                string planToSiteTime = "";
                //集散发网点是否延误
                if (UtilityHelp.Instance.isTerminalSendNextLate(resultBean, planNextJSTime, jsArrivalTime, jsDepTime, arListAllSite, htAllSiteTime, jsSite, dispatchSite, out planToSiteTime, dispatchSiteArrival))
                {
                    return true;
                }



                



            }
            catch (Exception ex)
            {

            }
            return res;
        }

        private bool isStayInCenterMoreThan1Day( ResultBean resultBean, ArrayList arListAllCenter,Hashtable htTaskTime)
        {
            bool res = false;
            try
            {
                int rowIndex = 0;
                foreach (string strCenter in arListAllCenter)
                {
                    if (rowIndex <1)
                    {
                        rowIndex++;
                        continue;
                    }
                    rowIndex++;
                    DbgBean dbgBean = new bean.DbgBean();
                    if(htTaskTime.ContainsKey(strCenter))
                    {
                        dbgBean = htTaskTime[strCenter] as DbgBean;
                        if (utility.Utility.isTimeRight(dbgBean.plannedArrivalTime)&& utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                        {
                            /*if(dbgBean.lastPlannedArrival < dbgBean.lastActArrival)
                            {
                                dbgBean.lastPlannedArrival = dbgBean.lastActArrival;
                            }*/
                            TimeSpan ts;
                            TimeSpan tsFirst = dbgBean.actualDepartureTime - dbgBean.plannedArrivalTime;
                            TimeSpan tsSecond;
                            ts = tsFirst;
                            int commonVal = 24;

                            if(resultBean.isReturnParcel)
                            {
                                return res;
                            }
                            if(resultBean.errorMsg.Contains("退回"))
                            {
                                commonVal = 48;
                            }
                            if (utility.Utility.isTimeRight(dbgBean.secondArrival) && utility.Utility.isTimeRight(dbgBean.secondDep))
                            {
                                tsSecond = dbgBean.secondDep - dbgBean.secondArrival;
                                if (tsSecond.TotalHours > commonVal)
                                {
                                    ts = tsSecond;
                                }
                            }
                            if (tsFirst.TotalHours > commonVal)
                            {
                                ts = tsFirst;
                            }
                           

                            if (ts.TotalHours> commonVal)
                            {
                                int day = ts.Days;
                                int hour = ts.Hours;
                                res = true;
                                if (resultBean.errorMsg.Contains("退回"))
                                {
                                    resultBean.errorType = "退回件滞留超时";
                                }
                                else
                                {
                                    resultBean.errorType = "非退回件滞留超时";
                                }
                                resultBean.dutySite = strCenter;
                                resultBean.errorMsg =  "超过"+ day.ToString() + "天"+ hour .ToString()+ "小时未发车";
                                
                                
                            }
                        }

                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }


        private bool isStayInSiteMoreThan1Day(ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime,Hashtable htTask)
        {
            bool res = false;
            try
            {
                int rowIndex = 0;
                foreach (string strCenter in arListAllSite)
                {
                   if(rowIndex<=1)
                   {
                        rowIndex++;
                        continue;
                   }
                    rowIndex++;
                    if(strCenter.Contains("网点"))
                    {
                        continue;
                    }
                    DbgBean dbgBean = new bean.DbgBean();
                    if (htSiteTime.ContainsKey(strCenter))
                    {
                        dbgBean = htSiteTime[strCenter] as DbgBean;

                        if(htTask.ContainsKey(strCenter))
                        {
                            dbgBean = htTask[strCenter] as DbgBean;
                            dbgBean.firstArrival = dbgBean.plannedArrivalTime;
                        }
                        if (utility.Utility.isTimeRight(dbgBean.firstArrival) && utility.Utility.isTimeRight(dbgBean.firstDep))
                        {
                            //TimeSpan ts = dbgBean.actualDepartureTime - dbgBean.actualArrivalTime;
                            int commonVal = 24;
                            if (resultBean.errorMsg.Contains("退回"))
                            {
                                commonVal = 24;
                            }
                            TimeSpan ts;
                            TimeSpan tsFirst = dbgBean.firstDep - dbgBean.firstArrival;
                            TimeSpan tsSecond;

                            ts = tsFirst;
                            if (utility.Utility.isTimeRight(dbgBean.secondArrival) && utility.Utility.isTimeRight(dbgBean.secondDep))
                            {
                                tsSecond = dbgBean.secondDep - dbgBean.secondArrival;
                                if (tsSecond.TotalHours > commonVal)
                                {
                                    ts = tsSecond;
                                }
                            }
                            if (tsFirst.TotalHours > commonVal)
                            {
                                ts = tsFirst;
                            }

                            if (ts.TotalHours > commonVal)
                            {
                                int day = ts.Days;
                                int hour = ts.Hours;
                                res = true;
                                resultBean.dutySite = strCenter;
                                if (resultBean.errorMsg.Contains("退回"))
                                {
                                    resultBean.errorType = "退回件滞留超时";
                                }
                                else
                                {
                                    resultBean.errorType = "非退回件滞留超时";
                                }
                                resultBean.errorMsg = "超过" + day.ToString() + "天" + hour.ToString() + "小时未发车";
                                
                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {

            }
            return res;
        }



        private bool isReturnParcel(ArrayList arListAllRoadMap, ResultBean resultBean, out bool isTransferDesChange,ArrayList arListAllGXDBORJBTask)
        {
            isTransferDesChange = false;
            bool res = false;
            string lastScanSite = "";
            bool containReturnScan = false;
            try
            {
                string desCenter = resultBean.errorMsg;
                
                foreach (RoadBean roadBean in arListAllRoadMap)
                {
                    string scanType = roadBean.scanTypeName;
                    if(scanType!=null&&scanType.Contains("退件扫描"))
                    {
                        containReturnScan = true;
                    }
                    if (scanType != null && scanType.Contains("退件登记"))
                    {
                        containReturnScan = true;
                    }
                    
                    if (roadBean.scanNetworkName!=""&& roadBean.scanNetworkName!=StoParams.Instance.register_site)
                    {
                        lastScanSite = roadBean.scanNetworkName;
                    }
                    if (scanType != null && scanType.Contains("转寄登记"))
                    {
                        isTransferDesChange = true;
                    }
                    if (roadBean.dkgx != "" && !arListAllGXDBORJBTask.Contains(roadBean.dkgx))
                    {
                        if(roadBean.dkgx.StartsWith("DB")|| roadBean.dkgx.StartsWith("DKDD") || roadBean.dkgx.StartsWith("JB") || roadBean.dkgx.StartsWith("DKGX") || roadBean.dkgx.StartsWith("WFGX"))
                        {
                            arListAllGXDBORJBTask.Add(roadBean.dkgx);
                        }
                        
                    }


                }
            }
            catch (Exception ex)
            {

            }
            if(lastScanSite==StoParams.Instance.register_site)
            {
                containReturnScan = true;
            }
            res = containReturnScan;
            return res;
        }


        private bool isGXContainSortWrong(Hashtable htGXCenter,ResultBean resultBean)
        {
            bool res = false;
            try
            {
                string desCenter = resultBean.errorMsg;
                if(desCenter.Contains(resultBean.dutySite)&& desCenter.Contains("错发"))
                {
                    desCenter = desCenter.Substring(desCenter.IndexOf("错发") + 2);
                    desCenter = desCenter.Substring(0, desCenter.IndexOf("中心") + 2).Trim();
                    string strDepCenter = resultBean.dutySite.Trim();
                    foreach(DictionaryEntry de in htGXCenter)
                    {
                        ArrayList arListCenters = (ArrayList)de.Value;
                        if (arListCenters.Contains(strDepCenter) && arListCenters.Contains(desCenter))
                        {
                            if (arListCenters.IndexOf(desCenter) > arListCenters.IndexOf(strDepCenter))
                            {
                                res = true;
                                break;
                            }

                        }
                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }

        private bool isTransferLong(ResultBean resultBean, ArrayList arListAllRoadMap)
        {
            bool res = false;
            try
            {
                int roadIndex = 0;
                ArrayList arListAllTransferCenter = new ArrayList();
                bool isChangeAddr = false;
                foreach (RoadBean roadBean in arListAllRoadMap)
                {
                    roadIndex++;
                    string nextName = roadBean.nextStopName;
                    string scanSiteName = roadBean.scanNetworkName;
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = "";
                    if (scanType.Contains("转寄登记") || scanType.Contains("退件"))
                    {
                        return res;
                    }

                    if ((scanType == "发件扫描" || scanType.ToString() == "装车发件") && nextName != ""&& (scanSiteName.Contains("转运中心")|| scanSiteName.Contains("分拨")) && (nextName.Contains("转运中心")|| nextName.Contains("分拨")))
                    {
                        if(UtilityHelp.Instance.isNextStopArrived(arListAllRoadMap, roadIndex, nextName))
                        {
                            if(!arListAllTransferCenter.Contains(scanSiteName))
                            {
                                arListAllTransferCenter.Add(scanSiteName);
                            }
                            if (!arListAllTransferCenter.Contains(nextName))
                            {
                                arListAllTransferCenter.Add(nextName);
                            }
                        }
                    }

                }
                for(int i=0;i< arListAllTransferCenter.Count;i++)
                {
                    if(i< arListAllTransferCenter.Count-1)
                    {
                        string curCenter = arListAllTransferCenter[i].ToString();
                        string nextsnextCenter= arListAllTransferCenter[i+2].ToString();
                        if(LoadBasicHelper.Instance.m_ht_main_effi.ContainsKey(curCenter))
                        {
                            Hashtable htCurAndNext = LoadBasicHelper.Instance.m_ht_main_effi[curCenter] as Hashtable;
                            if(htCurAndNext!=null)
                            {
                                string key = curCenter + "@" + nextsnextCenter;
                                if(htCurAndNext.ContainsKey(key))
                                {
                                    res = true;
                                    resultBean.errorMsg = curCenter + " 应直发" + nextsnextCenter;
                                    resultBean.dutySite = curCenter;
                                    return res;
                                }
                            }
                        }

                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;
                
        }



        /// <summary>
        /// 转运中心发转运中心延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isTransferCenterDelay(ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime,string terminalDepTime,ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival,bool isCruReturnParcel)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {
                if(!StoParams.Instance.isShowTransfer)
                {
                    return res;
                }

                if(isCruReturnParcel)
                {
                    return false;
                }
                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";
             
                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/

                int rowIndex = 0;

                ArrayList arListDelete = new ArrayList();
                foreach(string centerName in arListAllTaskCenters)
                {
                    if(!htSiteTime.ContainsKey(centerName))
                    {
                        arListDelete.Add(centerName);
                    }
                }
                foreach(string deleteKey in arListDelete)
                {
                    if(arListAllTaskCenters.Contains(deleteKey))
                    {
                        arListAllTaskCenters.Remove(deleteKey);
                    }
                }
                foreach(string centerName in arListAllTaskCenters)
                {
                    shouldDepTime = "";
                    string actDepTime = "";
                    if (rowIndex== arListAllTaskCenters.Count-1)
                    {
                        break;
                    }
                    string nextStopName = arListAllTaskCenters[rowIndex + 1].ToString();
                    DbgBean dbgTask = htAllTaskTime[centerName] as DbgBean;

                    DbgBean dbgActual = htSiteTime[centerName] as DbgBean;
                    if(dbgTask==null|| dbgActual==null)
                    {
                        rowIndex++;
                        continue;
                    }
                    DateTime dtActualDep = dbgTask.actualDepartureTime;
                    DateTime dtplanDep = dbgTask.plannedDepartureTime;
                    DateTime dtPlanArrival = dbgTask.plannedArrivalTime;
                    DateTime dtActualArrival = dbgTask.actualArrivalTime;

                    DateTime dtLastPlanArrival = dbgTask.lastPlannedArrival;
                    DateTime dtLastPlanDep = dbgTask.lastPlannedDepartureTime;
                    DateTime dtLastActArrival = dbgTask.lastActArrival;
                    DateTime dtLastActualDep = dbgTask.lastActualDepartureTime;

                    if(dtActualDep< dtLastActualDep)
                    {
                        dtActualDep = dtLastActualDep;
                    }
                    if (dtplanDep < dtLastPlanDep)
                    {
                        dtplanDep = dtLastPlanDep;
                    }

                    /*if (dtPlanArrival < dtLastPlanArrival)
                    {
                        dtPlanArrival = dtLastPlanArrival;
                    }*/

                    if (dtActualArrival < dtLastActArrival)
                    {
                        dtActualArrival = dtLastActArrival;
                    }

                    if (!utility.Utility.isTimeRight(dtPlanArrival))
                    {
                        rowIndex++;
                        continue;
                    }

                    

                    DateTime dtPlanDepTime= dtplanDep;

                    

                    DateTime dtConcute = dtPlanArrival;
                    if(dtActualArrival> dtConcute)
                    {
                        dtConcute = dtActualArrival;
                        htCarDelay[centerName] = centerName;
                    }

                    double addTime = 1;
                    if(StoParams.Instance.isUseOperationTime)
                    {
                        if(rowIndex>1)
                        {
                            string priorCenter = arListAllTaskCenters[rowIndex - 1].ToString();
                            addTime=UtilityHelp.Instance.getArrivaCenterAddHour(priorCenter, centerName, dtConcute.ToString());

                        }
                        else
                        {
                            addTime = 0;
                        }
                    }

                    //dtConcute = dtConcute.AddHours(addTime);


                    string planArrivalNextSiteConduct = "";

                    string planArrivalNextSiteUsingLateTime = "";
                    ArrayList arListNextStop = new ArrayList();
                    if (LoadBasicHelper.Instance.m_ht_main_effi.ContainsKey(centerName))
                    {
                        Hashtable htCenter = LoadBasicHelper.Instance.m_ht_main_effi[centerName] as Hashtable;
                        if(htCenter.ContainsKey(nextStopName))
                        {
                            arListNextStop = htCenter[nextStopName] as ArrayList;
                            shouldDepTime= UtilityHelp.Instance.getFirstCenterPlanDepTime(dtConcute, arListNextStop,out planArrivalNextSiteConduct);
                            //UtilityHelp.Instance.getFirstCenterPlanDepTime(dtConcute, arListNextStop, out planArrivalNextSiteUsingLateTime);
                        }
                    }
                    if(shouldDepTime!="")
                    {
                        DateTime dtShouldDep = Convert.ToDateTime(shouldDepTime);
                        bool isLatestSHZXTimeSame = false;
                        isLatestSHZXTimeSame = isNextSHZXTimeSame(arListNextStop, dtPlanDepTime, dtShouldDep);
                        if (!Utility.isTimeRight(dtPlanDepTime))
                        {
                            isLatestSHZXTimeSame = false;
                            if(Utility.isTimeRight(dtActualDep))
                            {
                                dtPlanDepTime = dtActualDep;
                            }
                            else
                            {
                                //缺少发件记录
                                DbgBean dbgNextTask = htAllTaskTime[nextStopName] as DbgBean;
                                string planDepNextCondut = "";
                                DateTime dtTmpPlanArrival = dbgNextTask.plannedArrivalTime;
                                if(!Utility.isTimeRight(dtTmpPlanArrival))
                                {
                                    dtTmpPlanArrival = dbgNextTask.actualArrivalTime;
                                }
                                UtilityHelp.Instance.getCenterPlanDepTimeByNextsiteArrivalTime(dtTmpPlanArrival, arListNextStop, out planDepNextCondut);
                                if(planDepNextCondut!="")
                                {
                                    dtPlanDepTime = Convert.ToDateTime(planDepNextCondut);
                                }

                            }
                            
                        }

                        if (dtPlanDepTime > dtShouldDep&& dtShouldDep.Date<Convert.ToDateTime(dispatchSiteArrival).Date
                            &&!isLatestSHZXTimeSame)
                        {
                           

                            res = true;
                            resultBean.dutySite = centerName;
                            resultBean.errorMsg = "中转延误，晚发" + nextStopName;
                            resultBean.errorType = "中转延误";
                            resultBean.shouldLeaveTime = dtShouldDep.ToString();
                            if (Utility.isTimeRight(dtActualDep))
                            {
                                /*if (dtActualDep < dtPlanDepTime)
                                {
                                    res = false;
                                }*/
                            }
                               
                            if (htCarDelay.ContainsKey(centerName))
                            {
                                resultBean.errorType = "中转延误"+" 班车延误";
                            }

                            if(planArrivalNextSiteConduct!=""&& dispatchSiteArrival!="")
                            {
                                if(Convert.ToDateTime(planArrivalNextSiteConduct).Date== Convert.ToDateTime(dispatchSiteArrival).Date)
                                {
                                    res = false;
                                }
                            }


                        }

                        if(res)
                        {
                            if(resultBean.errorMsg.Contains("中转延误，晚发"))
                            {
                                string lateToCenter = nextStopName;
                                if(arListAllTaskCenters[arListAllTaskCenters.Count-1].ToString()== nextStopName)
                                {
                                    ArrayList arListEffi = new ArrayList();
                                    if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lateToCenter))
                                    {
                                        Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[lateToCenter] as Hashtable;
                                        if (ht.ContainsKey(dispatchSite))
                                        {
                                            arListEffi = ht[dispatchSite] as ArrayList;
                                            string latestTime = UtilityHelp.Instance.getLastDispatchSiteArrival(arListEffi, dtPlanDepTime.ToString());
                                            string planArrivalCenterTime = getNextCenterArrivalTime(arListNextStop, dtPlanDepTime);
                                            string shouldArrivalCenterTime = getNextCenterArrivalTime(arListNextStop, dtShouldDep);
                                            if(planArrivalCenterTime!=""&& shouldArrivalCenterTime!="")
                                            {
                                                string dtPlanTime = Convert.ToDateTime(planArrivalCenterTime).ToShortTimeString().ToString();
                                                string dtShouldTime = Convert.ToDateTime(shouldArrivalCenterTime).ToShortTimeString().ToString();
                                                if(Convert.ToDateTime(planArrivalCenterTime).Date== Convert.ToDateTime(shouldArrivalCenterTime).Date)
                                                {
                                                    if (Convert.ToDateTime(dtPlanTime) < Convert.ToDateTime(latestTime)
                                                        && Convert.ToDateTime(dtShouldTime) < Convert.ToDateTime(latestTime))
                                                    {
                                                        res = false;
                                                    }
                                                }
                                                
                                            }

                                            



                                        }
                                    }

                                        

                                }
                            }


                        }

                        if(res)
                        {
                            //用正确的路由时间计算，如果正确的路由延误，则此转运不算延误
                            //用延迟的路由时间计算，如果延误的发件时间计算也不延误，则整体不延误，
                            //如果正常的不延误，延迟的发件延误，则算延误

                            DbgBean dbgNextStopTask = htAllTaskTime[nextStopName] as DbgBean;
                            string nextStopPlanArrival = dbgNextStopTask.lastPlannedArrival.ToString();
                            string planArrivalDispatchSite = "";
                            //UtilityHelp.Instance.getFirstCenterPlanDepTime(dtConcute, arListNextStop, out planArrivalNextSiteConduct);
                            //res=isReallyLateIfUsingRightPlan(arListAllSite, centerName, nextStopName, planArrivalNextSiteConduct, terminalDepTime, dbgActual.actualDepartureTime, dtPlanArrival);
                            bool isLateIfUsingRightPlan = isReallyLateIfUsingRightPlan(arListAllSite,  nextStopName, planArrivalNextSiteConduct, terminalDepTime, dispatchSite, dispatchSiteArrival,out planArrivalDispatchSite);

                            bool isLateIfUsingLatePlan = true;
                         
                            if (Convert.ToDateTime(nextStopPlanArrival).Date==Convert.ToDateTime(planArrivalNextSiteConduct).Date)
                            {
                                isLateIfUsingLatePlan = isReallyLateIfUsingRightPlan(arListAllSite, nextStopName, nextStopPlanArrival, terminalDepTime, dispatchSite, dispatchSiteArrival, out planArrivalDispatchSite);
                                if(Convert.ToDateTime(nextStopPlanArrival).Date == Convert.ToDateTime(dispatchSiteArrival).Date&& Convert.ToDateTime(dispatchSiteArrival).Hour<13)
                                {
                                    isLateIfUsingLatePlan = false;
                                }

                            }
                            //bool isLateIfUsingLatePlan = false;



                            if (isLateIfUsingRightPlan)
                            {
                                res=false;
                            }
                            else
                            {
                                if(isLateIfUsingLatePlan)
                                {
                                    return true;
                                }
                                else
                                {
                                    res = false;
                                }
                               
                            }

                        }

                   

                    }
                   


                    rowIndex++;




                }    

     


               



            }
            catch (Exception ex)
            {

            }
            return res;
        }


        /// <summary>
        /// 中转晚到件延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isTransferArrivalLate(ArrayList arListRoadMap, ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {
                if(resultBean.errorMsg.Contains("退回"))
                {
                    return false;
                }
                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";



                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/
                RoadBean priorDepBean = new RoadBean();
                RoadBean dispatchArrivalBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                bool isCenterAppera = false;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (roadBean.scanNetworkName.Contains("转运") || roadBean.scanNetworkName.Contains("分拨"))
                    {
                        if (!isCenterAppera)
                        {
                            isCenterAppera = true;
                            continue;
                        }

                    }
                    if (!isCenterAppera)
                    {
                        continue;
                    }
                    if (scanType.Contains("到件")&& (siteName.Contains("转运")|| siteName.Contains("分拨")))
                    {
                        string curArrival = scanTime;
                        int nextArrivalIndex = 0;
                        string nextArrival = "";
                        for(int m=i+1;m < arListRoadMap.Count; m++)
                        {
                            RoadBean mBean = (RoadBean)arListRoadMap[m];
                            if(mBean.scanTypeName.Contains("到件")&& mBean.scanNetworkName== siteName)
                            {
                                nextArrivalIndex = m-1;
                                nextArrival = mBean.scanTime;
                                break;
                            }
                        }
                        if(nextArrivalIndex>0)
                        {
                            bool findOtherSite = false;
                            for(int j=i+1;j<= nextArrivalIndex;j++)
                            {
                                RoadBean jBean = (RoadBean)arListRoadMap[j];
                                if(jBean.scanTypeName.Contains("发件")|| jBean.scanTypeName.Contains("到件") || jBean.scanTypeName.Contains("集包") || jBean.scanTypeName.Contains("入库"))
                                {
                                    if(jBean.scanNetworkName!= siteName)
                                    {
                                        findOtherSite = true;
                                        break;
                                    }
                                }
                            }
                            if(!findOtherSite)
                            {
                                TimeSpan ts = Convert.ToDateTime(nextArrival).Date.AddDays(0) - Convert.ToDateTime(curArrival).Date;
                                if (ts.TotalDays >= 2.5)
                                {
                                    res = true;
                                    resultBean.dutySite = siteName;
                                    resultBean.errorMsg = "转运晚到件 " + ts.TotalDays.ToString("#0.0") + " 天";
                                    resultBean.errorType = "转运晚到件";
                                    if (htAllTaskTime.ContainsKey(siteName))
                                    {
                                        DbgBean curDbg = htAllTaskTime[siteName] as DbgBean;
                                        if(curDbg.isHaveTwoTask)
                                        {
                                            resultBean.errorType = "转运晚发";
                                        }
                                    }
                                    
                                    if (resultBean.delayDays == ""|| resultBean.delayDays == "0")
                                    {
                                        resultBean.delayDays = ts.TotalDays.ToString("#0.0");
                                    }
                                    return res;
                                }
                            }
                        }
                    }
                }
            




    


            }
            catch (Exception ex)
            {

            }
            return res;
        }




        /// <summary>
        /// 末端非退回晚到件延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isSiteArrivalLate(ArrayList arListRoadMap, ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/
           

                RoadBean priorDepBean = new RoadBean();
                RoadBean dispatchArrivalBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                bool isCenterAppera = false;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (roadBean.scanNetworkName.Contains("转运") || roadBean.scanNetworkName.Contains("分拨"))
                    {
                        if (!isCenterAppera)
                        {
                            isCenterAppera = true;
                            continue;
                        }

                    }
                    if (!isCenterAppera)
                    {
                        continue;
                    }
                    if (nextName != "" && scanType.Contains("发件") && nextName.Contains("网点"))
                    {
                        dispatchSite = nextName;
                        break;
                    }
                }
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (nextName != "" && scanType.Contains("发件") && nextName == dispatchSite)
                    {
                        priorDepBean = roadBean;
                    }

                    if (siteName == dispatchSite && scanType.Contains("到件") || scanType.Contains("入库"))
                    {
                        if (dispatchArrivalBean.scanTime == "")
                        {
                            dispatchArrivalBean = roadBean;
                            break;
                        }
                    }
                }




                lastCenter = priorDepBean.scanNetworkName;
                if (priorDepBean.nextStopName.Contains("网点") || priorDepBean.nextStopName.Contains("集散"))
                {
                    string nextSite = priorDepBean.nextStopName;
                    ArrayList arListEffi = new ArrayList();
                    if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lastCenter))
                    {
                        Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[lastCenter] as Hashtable;
                        if (ht.ContainsKey(nextSite))
                        {
                            arListEffi = ht[nextSite] as ArrayList;
                        }
                    }
                    string latestArrivalTime = "";
                    if (arListEffi.Count > 0)
                    {
                        latestArrivalTime = UtilityHelp.Instance.getMostRecentArrivaTime(Convert.ToDateTime(priorDepBean.scanTime), arListEffi);
                    }
                    else
                    {
                        latestArrivalTime = Convert.ToDateTime(Convert.ToDateTime(priorDepBean.scanTime).AddDays(1)).ToString();
                    }

                    if(dispatchArrivalBean.scanNetworkName!= priorDepBean.nextStopName)
                    {
                        return false;
                    }
                    TimeSpan ts = Convert.ToDateTime(dispatchArrivalBean.scanTime).Date.AddDays(0) - Convert.ToDateTime(latestArrivalTime).Date;
                    if (ts.TotalDays >= 1)
                    {
                        if (dispatchArrivalBean.scanNetworkName != StoParams.Instance.register_site)
                        {
                            if (resultBean.errorType.Contains("错"))
                            {
                                if (ts.TotalDays < 2)
                                {
                                    return false;
                                }
                            }
                            res = true;
                            resultBean.dutySite = dispatchSite;
                            resultBean.errorMsg = "末端晚到件 " + ts.TotalDays.ToString("#0.0") + " 天";
                            resultBean.errorType = "末端晚到件";
                            if (resultBean.delayDays == "")
                            {
                                resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(latestArrivalTime), Convert.ToDateTime(dispatchArrivalBean.scanTime).Date.AddDays(1)).ToString();
                            }
                        }
                        
                    }
                }



            }
            catch (Exception ex)
            {

            }
            return res;
        }


        /// <summary>
        /// 末端退回晚到件延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isInterceptSiteArrivalLate(ArrayList arListRoadMap, ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/
                if(!resultBean.errorType.Contains("退回")&& !resultBean.errorMsg.Contains("退回"))
                {
                    return res;
                }

                RoadBean priorDepBean = new RoadBean();
                RoadBean dispatchArrivalBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                bool isCenterAppera = false;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (roadBean.scanNetworkName.Contains("转运")|| roadBean.scanNetworkName.Contains("分拨"))
                    {
                        if(!isCenterAppera)
                        {
                            isCenterAppera = true;
                            continue;
                        }
                        
                    }
                    if (!isCenterAppera)
                    {
                        continue;
                    }
                    if (nextName != "" && scanType.Contains("发件")&& nextName.Contains("网点"))
                    {
                        dispatchSite = nextName;
                        break;
                    }
                }
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (nextName != "" && scanType.Contains("发件") && nextName==dispatchSite)
                    {
                        priorDepBean = roadBean;                       
                    }

                    if(siteName== dispatchSite&& scanType.Contains("到件")||scanType.Contains("入库"))
                    {
                        if(dispatchArrivalBean.scanTime=="")
                        {
                            dispatchArrivalBean = roadBean;
                            break;
                        }
                    }                 
                }

                if(dispatchArrivalBean.scanTime=="")
                {
                    for (int i = 0; i < arListRoadMap.Count; i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        string siteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string scanTime = roadBean.scanTime;
              

                        if (siteName == dispatchSite)
                        {
                            if (dispatchArrivalBean.scanTime == "")
                            {
                                dispatchArrivalBean = roadBean;
                                break;
                            }
                        }
                    }

                }
     
  

     
                lastCenter = priorDepBean.scanNetworkName;
                if (priorDepBean.nextStopName.Contains("网点") || priorDepBean.nextStopName.Contains("集散"))
                {
                    string nextSite = priorDepBean.nextStopName;
                    ArrayList arListEffi = new ArrayList();
                    if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lastCenter))
                    {
                        Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[lastCenter] as Hashtable;
                        if (ht.ContainsKey(nextSite))
                        {
                            arListEffi = ht[nextSite] as ArrayList;
                        }
                    }
                    string latestArrivalTime = "";
                    if (arListEffi.Count > 0)
                    {                      
                        latestArrivalTime = UtilityHelp.Instance.getMostRecentArrivaTime(Convert.ToDateTime(priorDepBean.scanTime), arListEffi);
                    }
                    else
                    {
                        latestArrivalTime = Convert.ToDateTime(Convert.ToDateTime(priorDepBean.scanTime).AddDays(1)).ToString();
                    }
                    TimeSpan ts = Convert.ToDateTime(dispatchArrivalBean.scanTime).Date.AddDays(0) - Convert.ToDateTime(latestArrivalTime).Date;
                    if (ts.TotalDays >= 1)
                    {
                        if(dispatchArrivalBean.scanNetworkName!=StoParams.Instance.register_site)
                        {
                            res = true;
                            resultBean.dutySite = dispatchSite;
                            resultBean.errorMsg = "末端晚到件 " + ts.TotalDays.ToString("#0.0") + " 天";
                            resultBean.errorType = "末端晚到件";
                            if (resultBean.delayDays == "")
                            {
                                resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(latestArrivalTime), Convert.ToDateTime(dispatchArrivalBean.scanTime).Date.AddDays(1)).ToString();
                            }
                        }
                        
                    }
                }

   

            }
            catch (Exception ex)
            {

            }
            return res;
        }



        /// <summary>
        /// 末端无操作延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isSiteNoActlLate(ArrayList arListRoadMap, ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/

                if (!resultBean.errorType.Contains("退回"))
                {
                    return res;
                }

                RoadBean priorDepBean = new RoadBean();
                RoadBean dispatchArrivalBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                bool isCenterAppera = false;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (roadBean.scanNetworkName.Contains("转运") || roadBean.scanNetworkName.Contains("分拨"))
                    {
                        if (!isCenterAppera)
                        {
                            isCenterAppera = true;
                            continue;
                        }

                    }
                    if (!isCenterAppera)
                    {
                        continue;
                    }
                    if (nextName != "" && scanType.Contains("发件") && nextName.Contains("网点"))
                    {
                        dispatchSite = nextName;
                        break;
                    }
                }


                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    RoadBean priorBean = new RoadBean();
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (i > 2)
                    {
                        priorBean = (RoadBean)arListRoadMap[i - 1];
                    }
                    if ((scanType.Contains("问题件扫描") && roadBean.waybillTrackingContent.Contains("退回件")) ||
                        (scanType.Contains("拦截件登记")) && siteName == StoParams.Instance.register_site)
                    {
                        if (priorBean.scanTypeName.Contains("出仓扫描"))
                        {
                            TimeSpan ts = Convert.ToDateTime(scanTime).Date.AddDays(0) - Convert.ToDateTime(priorBean.scanTime).Date;
                            if (ts.TotalDays >= 2)
                            {
                                res = true;
                                resultBean.dutySite = dispatchSite;
                                resultBean.errorMsg = "末端派件延误 " + ts.TotalDays.ToString("#0.0") + " 天";
                                resultBean.errorType = "末端派件延误";
                                if (resultBean.delayDays == "")
                                {
                                    resultBean.delayDays = ts.TotalDays.ToString("#0.0");
                                }
                                return true;
                            }
                        }
                    }
                }

                int curArrIndex = 0;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (nextName != "" && scanType.Contains("发件") && nextName == dispatchSite)
                    {
                        priorDepBean = roadBean;
                    }

                    if (siteName == dispatchSite && scanType.Contains("到件"))
                    {
                        if (dispatchArrivalBean.scanTime == "")
                        {
                            curArrIndex = i;
                            dispatchArrivalBean = roadBean;
                            break;
                        }
                    }
                }

                bool isRCApprar = false;
                RoadBean rdRCBean = new RoadBean();
                string interptTime = "";
                for (int m = curArrIndex + 1; m < arListRoadMap.Count; m++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[m];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (siteName == dispatchSite && (scanType.Contains("入仓") || scanType.Contains("出仓")) ||
                        roadBean.waybillTrackingContent.Contains("派送") || roadBean.waybillTrackingContent.Contains("签收"))
                    {
                        isRCApprar = true;
                        rdRCBean = roadBean;
                    }
                    if (scanType.Contains("拦截件登记"))
                    {
                        interptTime = scanTime;
                        break;
                    }
                }

                if (!isRCApprar && interptTime != "")
                {
                    TimeSpan ts = Convert.ToDateTime(interptTime).Date.AddDays(0) - Convert.ToDateTime(dispatchArrivalBean.scanTime).Date;
                    if (dispatchArrivalBean.scanNetworkName != StoParams.Instance.register_site)
                    {
                        if (ts.TotalDays >= 1)
                        {
                            res = true;
                            resultBean.dutySite = dispatchSite;
                            resultBean.errorMsg = "末端晚到件 " + ts.TotalDays.ToString("#0.0") + " 天";
                            resultBean.errorType = "末端晚到件";
                            if (resultBean.delayDays == "")
                            {
                                resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(dispatchArrivalBean.scanTime), Convert.ToDateTime(interptTime).Date.AddDays(0)).ToString();
                            }
                        }
                    }
                     
                }


            }
            catch (Exception ex)
            {

            }
            return res;
        }


        /// <summary>
        /// 退回件末端无操作延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isInterCeptSiteNoActlLate(ArrayList arListRoadMap, ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/

                if (!resultBean.errorType.Contains("退回"))
                {
                    return res;
                }

                RoadBean priorDepBean = new RoadBean();
                RoadBean dispatchArrivalBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                bool isCenterAppera = false;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (roadBean.scanNetworkName.Contains("转运") || roadBean.scanNetworkName.Contains("分拨"))
                    {
                        if(!isCenterAppera)
                        {
                            isCenterAppera = true;
                            continue;
                        }
                        
                    }
                    if (!isCenterAppera)
                    {
                        continue;
                    }
                    if (nextName != "" && scanType.Contains("发件") && nextName.Contains("网点"))
                    {
                        dispatchSite = nextName;
                        break;
                    }
                }


                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    RoadBean priorBean = new RoadBean();
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if(i>2)
                    {
                        priorBean= (RoadBean)arListRoadMap[i-1];
                    }
                    if((scanType.Contains("问题件扫描")&& roadBean.waybillTrackingContent.Contains("退回件"))||
                        (scanType.Contains("拦截件登记"))&& siteName==StoParams.Instance.register_site)
                    {
                        if(priorBean.scanTypeName.Contains("出仓扫描"))
                        {
                            TimeSpan ts = Convert.ToDateTime(scanTime).Date.AddDays(0) - Convert.ToDateTime(priorBean.scanTime).Date;
                            if (ts.TotalDays >= 2)
                            {
                                res = true;
                                resultBean.dutySite = dispatchSite;
                                resultBean.errorMsg = "末端派件延误 " + ts.TotalDays.ToString("#0.0") + " 天";
                                resultBean.errorType = "末端派件延误";
                                if (resultBean.delayDays == "")
                                {
                                    resultBean.delayDays = ts.TotalDays.ToString("#0.0");
                                }
                                return true;
                            }
                        }
                    }
                }

                int curArrIndex = 0;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (nextName != "" && scanType.Contains("发件") && nextName == dispatchSite)
                    {
                        priorDepBean = roadBean;
                    }

                    if (siteName == dispatchSite && scanType.Contains("到件"))
                    {
                        if (dispatchArrivalBean.scanTime == "")
                        {
                            curArrIndex = i;
                            dispatchArrivalBean = roadBean;
                            break;
                        }
                    }
                }

                bool isRCApprar = false;
                RoadBean rdRCBean = new RoadBean();
                string interptTime = "";
                for (int m= curArrIndex+1;m< arListRoadMap.Count;m++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[m];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if(siteName== dispatchSite&&(scanType.Contains("入仓")|| scanType.Contains("出仓"))||
                        roadBean.waybillTrackingContent.Contains("派送")|| roadBean.waybillTrackingContent.Contains("签收"))
                    {
                        isRCApprar = true;
                        rdRCBean = roadBean;
                    }
                    if(scanType.Contains("拦截件登记"))
                    {
                        interptTime = scanTime;
                        break;
                    }
                }

                if(!isRCApprar&& interptTime!="")
                {
                    TimeSpan ts = Convert.ToDateTime(interptTime).Date.AddDays(0) - Convert.ToDateTime(dispatchArrivalBean.scanTime).Date;
                    if (ts.TotalDays >= 1)
                    {
                        if (dispatchArrivalBean.scanNetworkName != StoParams.Instance.register_site)
                        {
                            res = true;
                            resultBean.dutySite = dispatchSite;
                            resultBean.errorMsg = "末端晚到件 " + ts.TotalDays.ToString("#0.0") + " 天";
                            resultBean.errorType = "末端晚到件";
                            if (resultBean.delayDays == "")
                            {
                                resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(dispatchArrivalBean.scanTime), Convert.ToDateTime(interptTime).Date.AddDays(0)).ToString();
                            }
                        }
                           
                    }
                }


            }
            catch (Exception ex)
            {

            }
            return res;
        }



        /// <summary>
        /// 退回延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isSiteReturnDelay(ArrayList arListRoadMap, ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {
               
                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/
                RoadBean priorDepBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (nextName != "" && scanType.Contains("发件")&& regInterCeptTime=="")
                    {
                        priorDepBean = roadBean;
                    }
                    //if (roadBean.scanNetworkName == StoParams.Instance.register_site)
                    {
                        if (roadBean.scanTypeName != null && (roadBean.scanTypeName == "拦截件登记" || roadBean.scanTypeName == "退件登记"))
                        {
                            curIndex = i;
                            regInterCeptTime = roadBean.scanTime;
                        }
                        /*else if (roadBean.scanTypeName != null && (roadBean.scanTypeName == "拦截件撤销"))
                        {
                            curIndex = 0;
                            regInterCeptTime = "";
                        }*/
                    }
                }
                if(regInterCeptTime=="")
                {
                    return false;
                }
                string terMinalLeaver = "";
                for(int i= curIndex;i< arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (nextName != "" && scanType.Contains("发件") && siteName == priorDepBean.nextStopName)
                    {
                        terMinalLeaver = scanTime;
                    }
                }

                if(terMinalLeaver=="")
                {
                    for (int i = curIndex; i < arListRoadMap.Count; i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        string siteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string scanTime = roadBean.scanTime;
                        if (scanType.Contains("到件") && siteName == priorDepBean.scanNetworkName)
                        {
                            terMinalLeaver = scanTime;
                            break;
                        }
                    }
                    if(terMinalLeaver=="")
                    {
                        terMinalLeaver = System.DateTime.Now.ToString();
                    }
                    
                }
                lastCenter = priorDepBean.scanNetworkName;
                if (priorDepBean.nextStopName.Contains("网点")|| priorDepBean.nextStopName.Contains("集散"))
                {
                    string nextSite = priorDepBean.nextStopName;
                    ArrayList arListEffi = new ArrayList();
                    if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lastCenter))
                    {
                        Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[lastCenter] as Hashtable;
                        if (ht.ContainsKey(nextSite))
                        {
                            arListEffi = ht[nextSite] as ArrayList;
                        }
                    }
                    string latestArrivalTime = "";
                    if (arListEffi.Count > 0)
                    {
                        latestArrivalTime = UtilityHelp.Instance.getMostRecentArrivaTime(Convert.ToDateTime(priorDepBean.scanTime), arListEffi);
                    }
                    else
                    {
                        latestArrivalTime = Convert.ToDateTime(Convert.ToDateTime(priorDepBean.scanTime).AddDays(1)).ToString();
                    }
                    TimeSpan ts = Convert.ToDateTime(terMinalLeaver).Date.AddDays(1) - Convert.ToDateTime(latestArrivalTime).Date;
                    if(ts.TotalDays>3)
                    {
                        res = true;
                        resultBean.dutySite = priorDepBean.nextStopName;
                        resultBean.errorMsg = "退回，晚发" + ts.TotalDays.ToString("#0.0")+" 天";
                        resultBean.errorType = "退回延误";
                        if (resultBean.delayDays == "")
                        {
                            resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(latestArrivalTime), Convert.ToDateTime(terMinalLeaver).Date.AddDays(1)).ToString();
                        }
                    }                   
                }

                else if (priorDepBean.nextStopName.Contains("转运中心")|| priorDepBean.nextStopName.Contains("分拨"))
                {
                    string nextSite = priorDepBean.nextStopName;
                    ArrayList arListEffi = new ArrayList();
                    if (LoadBasicHelper.Instance.m_ht_main_effi.ContainsKey(lastCenter))
                    {
                        Hashtable ht = LoadBasicHelper.Instance.m_ht_main_effi[lastCenter] as Hashtable;
                        if (ht.ContainsKey(nextSite))
                        {
                            arListEffi = ht[nextSite] as ArrayList;
                        }
                    }
                    string latestArrivalTime = "";
                    latestArrivalTime = Convert.ToDateTime(Convert.ToDateTime(priorDepBean.scanTime).AddDays(2)).ToString();
                    TimeSpan ts = Convert.ToDateTime(terMinalLeaver) - Convert.ToDateTime(latestArrivalTime);
                    if (ts.TotalHours > 48)
                    {
                        res = true;
                        resultBean.dutySite = priorDepBean.nextStopName;
                        resultBean.errorMsg = "退回，晚发" + ts.TotalDays.ToString("#0.0") + " 天";
                        resultBean.errorType = "退回延误";

                        if (resultBean.delayDays == "")
                        {
                            resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(latestArrivalTime), Convert.ToDateTime(terMinalLeaver)).ToString();
                        }

                    }
                }


            }
            catch (Exception ex)
            {

            }
            return res;
        }

        private int getOutDelayDays(ArrayList arListRoadMap,out bool isReallyLate, ArrayList arListProblemScan)
        {
            int res = 0;
            isReallyLate = true;
            try
            {
                string outSite = "";
                DateTime dtOutSite = System.DateTime.Now;
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if(scanType.Contains("取出"))
                    {
                        outSite = siteName;
                        dtOutSite = Convert.ToDateTime(scanTime);
                        continue;
                    }
                    if(outSite!=""&& siteName== outSite)
                    {
                        if(scanType.Contains("问题件"))
                        {
                            TimeSpan ts = Convert.ToDateTime(scanTime) - dtOutSite;
                            if(ts.TotalHours<16)
                            {
                                if(dtOutSite.Hour>18&& Convert.ToDateTime(scanType).Hour<10)
                                {
                                   if(arListProblemScan.Count>=2)
                                    {
                                        isReallyLate = false;
                                        return res;

                                    }

                                }
                            }
                            else
                            {
                                res = (int)ts.TotalDays;
                            }
                        }
                    }
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }


        /// <summary>
        /// 私自退回延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isSelfReturnDelay(ArrayList arListRoadMap, ResultBean resultBean, ArrayList arListAllSite, 
            Hashtable htSiteTime, Hashtable htAllTaskTime, string terminalDepTime,
            ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival,string lanshouSite)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/
                RoadBean priorDepBean = new RoadBean();

                RoadBean interCeptBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                string interCeptScanSite = "";
                bool hasArrivalSite = false;
                string siteSendTime = "";
                string firstSite = "";

                Hashtable htInterceptSite = new Hashtable();
                Hashtable htPriorBean = new Hashtable();
                bool nextStopSiteAppear = false;
                Hashtable htProblemScaned = new Hashtable();
                Hashtable htNoreason = new Hashtable();
                bool hasSelfReturned = false;
                bool isOutWarehouse = false;
                string outScanTime = "";

                
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;

                    if(scanType.Contains("快件取出扫描"))
                    {
                        isOutWarehouse = true;
                        outScanTime = scanTime;
                    }
                    if ((scanType.Contains("拦截件登记")|| (scanType.Contains("问题件扫描")) && siteName == StoParams.Instance.register_site))
                    {
                        if (interCeptBean.scanTime == ""&& !hasSelfReturned)
                        {
                            interCeptBean = roadBean;
                            return false;
                        }

                    }
                    if(scanType.Contains("问题件扫描"))
                    {

                        if(!UtilityHelp.Instance.isNoNeedContinueProblem(roadBean))
                        {
                            if(i< (arListRoadMap.Count-2))
                            {
                                RoadBean roadBeanNext = (RoadBean)arListRoadMap[i + 1];
                               
                                if (roadBean.scanNetworkName != StoParams.Instance.register_site)
                                {
                                    if(!roadBeanNext.waybillTrackingContent.Contains("问题件扫描"))
                                    {
                                        htNoreason[siteName] = "";
                                        continue;
                                    }
                                    else
                                    {
                                        if(!roadBeanNext.waybillTrackingContent.Contains("无人接听")&&!roadBeanNext.waybillTrackingContent.Contains("更改派送时间"))
                                        {
                                            htNoreason[siteName] = "";
                                            continue;
                                        }
                                    }

                                   
                                }

                            }
                        


                           
                            
                        }
                        /*if(roadBean.waybillTrackingContent.Contains("校园件")|| roadBean.waybillTrackingContent.Contains("有发件未")
                            || roadBean.waybillTrackingContent.Contains("无人接听")|| roadBean.waybillTrackingContent.Contains("客户不在")
                            || roadBean.waybillTrackingContent.Contains("更改派送时间")|| roadBean.waybillTrackingContent.Contains("工作量")
                            || roadBean.waybillTrackingContent.Contains("自提"))*/
                        else
                        {
                            if (!htProblemScaned.ContainsKey(siteName))
                            {
                                ArrayList arListRoadBeans = new ArrayList();
                                arListRoadBeans.Add(roadBean);
                                htProblemScaned[siteName] = arListRoadBeans;
                            }
                            else
                            {
                                ArrayList arListRoadBeans = htProblemScaned[siteName] as ArrayList;
                                arListRoadBeans.Add(roadBean);

                            }
                        }
                        
                    }
                    if (nextName != "" && scanType.Contains("发件") && regInterCeptTime == "")
                    {
                        priorDepBean = roadBean;
                    }

        


                    if (siteName.Contains("网点") && (scanType.Contains("发件")) && siteName != StoParams.Instance.register_site)
                    {
                        siteSendTime = scanTime;
                        firstSite = siteSendTime;
                    }

          
                    if (roadBean.scanTypeName != null && (roadBean.scanTypeName =="退件扫描" && roadBean.scanNetworkName != StoParams.Instance.register_site))
                    {
                        if (!htInterceptSite.ContainsKey(siteName)&& siteName.Contains("网点"))
                        {
                            if(interCeptBean.scanTime == "")
                            {
                                hasSelfReturned = true;
                            }
                            curIndex = i;
                            regInterCeptTime = roadBean.scanTime;
                            interCeptScanSite = roadBean.scanNetworkName;
                            htInterceptSite[siteName] = i.ToString();

                            RoadBean rb = new RoadBean();
                            rb.scanNetworkName = priorDepBean.scanNetworkName;
                            rb.scanTime = priorDepBean.scanTime;
                            rb.nextStopName = priorDepBean.nextStopName;
                            if (rb.nextStopName == siteName)
                            {
                                htPriorBean[siteName] = rb;
                            }

                        }



                    }
                }
                if (regInterCeptTime == "")
                {
                    return false;
                }
                ArrayList arListDepSites = new ArrayList();
                foreach (string site in htInterceptSite.Keys)
                {
                    string curRow = htInterceptSite[site].ToString();
                    RoadBean curBean = (RoadBean)arListRoadMap[Convert.ToInt32(curRow)];

                    if (site.Contains("网点"))
                    {
                        for (int m = Convert.ToInt32(curRow) + 1; m < arListRoadMap.Count; m++)
                        {
                            RoadBean roadBean = (RoadBean)arListRoadMap[m];
                            if (roadBean.scanNetworkName == curBean.scanNetworkName && roadBean.scanTypeName.Contains("发件"))
                            {
                                if(!arListDepSites.Contains(site))
                                {
                                    arListDepSites.Add(site);
                                }
                                
                            }     

                        
                        }

                    }


                }

                foreach(string strSite in arListDepSites)
                {
                    if(htNoreason.ContainsKey(strSite))
                    {
                        continue;
                    }
                    
                    if(htProblemScaned.ContainsKey(strSite))
                    {
                        ArrayList arListProblemScan = htProblemScaned[strSite] as ArrayList;
                        RoadBean lastRoadBean = (RoadBean)arListProblemScan[arListProblemScan.Count - 1];

                     

                        if (arListProblemScan.Count<3)
                        {
                            resultBean.dutySite = strSite;
                            resultBean.errorType = "私自退回";
                            resultBean.delayDays = "";
                            resultBean.errorMsg = "私自退回";
                            if(lanshouSite.Contains("江东")&& isOutWarehouse)
                            {
                                resultBean.errorType = "快递柜取出";
                                resultBean.delayDays = "";
                                resultBean.errorMsg = "快递柜取出";
                            }
                            bool reaLate = false;
                            int delayDays = getOutDelayDays(arListRoadMap, out reaLate, arListProblemScan);
                            if(reaLate)
                            {
                                resultBean.delayDays = delayDays.ToString();
                                return true;
                            }
                            
                        }
                        string lastScanDateTime = "";
                        int cotinueDays = 0;

                        if(isOutWarehouse)
                        {
                            DateTime dtOut = Convert.ToDateTime(outScanTime);
                            ArrayList arListTodel = new ArrayList();
                            foreach (RoadBean roadBean in arListProblemScan)
                            {
                                if(Convert.ToDateTime(roadBean.scanTime)< dtOut)
                                {
                                    TimeSpan tsT = dtOut - (Convert.ToDateTime(roadBean.scanTime));
                                    if(tsT.TotalDays>1)
                                    {
                                        //arListTodel.Add(roadBean);
                                    }
                                }
                            }
                            foreach(RoadBean roadDel in arListTodel)
                            {
                                if(arListProblemScan.Contains(roadDel))
                                {
                                    arListProblemScan.Remove(roadDel);
                                }
                                
                            }

                        }
                        foreach(RoadBean roadBean in arListProblemScan)
                        {
                            if(roadBean.scanTime!="")
                            {
                                if(lastScanDateTime=="")
                                {
                                    lastScanDateTime = roadBean.scanTime;
                                    cotinueDays = 1;
                                    continue;
                                }
                                else
                                {
                                    TimeSpan ts = Convert.ToDateTime(Convert.ToDateTime(roadBean.scanTime).ToShortDateString()) - Convert.ToDateTime(Convert.ToDateTime(lastScanDateTime).ToShortDateString());
                                    if (ts.TotalDays == 1)
                                    {
                                        lastScanDateTime = roadBean.scanTime;
                                        cotinueDays++;
                                    }
                                    else if(ts.TotalDays > 1)
                                    {
                                        if(cotinueDays<3)
                                        {
                                            cotinueDays = 1;
                                        }
                                        
                                    }
                                }
                            }
                        }
                        if(cotinueDays<3)
                        {
                            resultBean.dutySite = strSite;
                            resultBean.errorType = "私自退回";
                            resultBean.delayDays = "";
                            resultBean.errorMsg = "私自退回";

                            if (lanshouSite.Contains("江东") && isOutWarehouse)
                            {
                                resultBean.errorType = "快递柜取出";
                                resultBean.delayDays = "";
                                resultBean.errorMsg = "快递柜取出";
                            }
                            bool reaLate = false;
                            int delayDays = getOutDelayDays(arListRoadMap, out reaLate, arListProblemScan);
                            if (reaLate)
                            {
                                resultBean.delayDays = delayDays.ToString();
                                return true;
                            }
                           
                        }

                    }
                }

                




            }
            catch (Exception ex)
            {

            }
            return res;
        }

       /// <summary>
       /// 判断是否是彻底延误，如果网点没做入库，只做了出库，最后又退回的，算是彻底延误
       /// </summary>
       /// <param name="arListRoadMap"></param>
       /// <param name="resultBean"></param>
       /// <param name="arListAllSite"></param>
       /// <param name="htSiteTime"></param>
       /// <param name="htAllTaskTime"></param>
       /// <param name="terminalDepTime"></param>
       /// <param name="arListAllTaskCenters"></param>
       /// <param name="dispatchSite"></param>
       /// <param name="dispatchSiteArrival"></param>
       /// <returns></returns>
        private bool isDispatchSiteDelayTooLong(ArrayList arListRoadMap, ResultBean resultBean)
        {
            //lock(objLock)
            {
                bool res = false;
                string shouldDepTime = "";
                try
                {
                    if (resultBean.wayBillNo == "JT2960743864259")
                    {
                        logHelp.LogHelper.Instance.writeLog("测试站点:" + StoParams.Instance.register_site+" arListCount="+ arListRoadMap.Count.ToString());
                    }

                    string jsSite = "";
                    string lastCenter = "";
                    string lastCenterDepTime = "";
                    string lastCenterPlanArriveTime = "";
                    string lastCenterActArriveTime = "";

                    Hashtable htCarDelay = new Hashtable();

                    RoadBean priorDepBean = new RoadBean();

                    RoadBean interCeptBean = new RoadBean();
                    string regInterCeptTime = "";
                    int curIndex = 0;
                    string interCeptScanSite = "";
                    bool hasArrivalSite = false;
                    string siteSendTime = "";
                    string firstSite = "";

                    Hashtable htInterceptSite = new Hashtable();
                    Hashtable htPriorBean = new Hashtable();
                    bool nextStopSiteAppear = false;
                    Hashtable htProblemScaned = new Hashtable();
                    string wareOutScanTime = "";
                    string interceptScanTime = "";
                    string arrivalScanTime = "";
                    string wareOutScanSite = "";
                    string depToDispatchSite = "";

                    string dispatchInwareTime = "";
                    string lastUsefulSite = "";

                    RoadBean roadBeanRegSiteIntercept = new RoadBean();

                    RoadBean roadSiteDepBean = new RoadBean();

                    RoadBean lastOtherSiteRoadBean = new RoadBean();


                    for (int i = 0; i < arListRoadMap.Count; i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        string siteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string scanTime = roadBean.scanTime;
                        if (siteName != "" && siteName != StoParams.Instance.register_site)
                        {
                            lastUsefulSite = siteName;
                            lastOtherSiteRoadBean = roadBean;
                        }
                        if ((scanType.Contains("退件登记") || scanType.Contains("拦截件登记")) || (scanType.Contains("问题件扫描") && roadBean.waybillTrackingContent.Contains("退回")))
                        {
                            if (siteName == StoParams.Instance.register_site)
                            {
                                if (roadBeanRegSiteIntercept.scanTime == "")
                                {
                                    roadBeanRegSiteIntercept = roadBean;
                                }

                                if (lastOtherSiteRoadBean.scanTypeName.Contains("发件") || lastOtherSiteRoadBean.scanTypeName.Contains("到件") || lastOtherSiteRoadBean.scanTypeName.Contains("出仓"))
                                {
                                    TimeSpan tsC = Convert.ToDateTime(roadBeanRegSiteIntercept.scanTime).Date - Convert.ToDateTime(lastOtherSiteRoadBean.scanTime).Date;
                                    if (tsC.TotalDays > 4)
                                    {
                                        for (int m = i + 1; m < arListRoadMap.Count; m++)
                                        {
                                            RoadBean mBean = (RoadBean)arListRoadMap[i];
                                            if (mBean.scanTypeName.Contains("发件"))
                                            {
                                                string lastUseFulScanTime = lastOtherSiteRoadBean.scanTime;
                                                if (lastOtherSiteRoadBean.scanTypeName.Contains("发件"))
                                                {
                                                    lastUseFulScanTime = Convert.ToDateTime(lastOtherSiteRoadBean.scanTime).AddDays(1).ToString();
                                                }
                                                TimeSpan tsD = Convert.ToDateTime(mBean.scanTime).Date - Convert.ToDateTime(lastOtherSiteRoadBean.scanTime).Date;
                                                if (tsD.TotalDays >= 7)
                                                {
                                                    resultBean.dutySite = mBean.scanNetworkName;
                                                    resultBean.delayDays = ((int)tsD.TotalDays).ToString();
                                                    resultBean.errorType = "彻底延误";
                                                    resultBean.errorMsg = "彻底延误";

                                                    return true;
                                                }

                                            }
                                        }
                                    }
                                }

                                break;


                            }
                        }


                    }






                    for (int i = 0; i < arListRoadMap.Count; i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        string siteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string scanTime = roadBean.scanTime;
                        if (siteName != "" && siteName != StoParams.Instance.register_site)
                        {
                            lastUsefulSite = siteName;
                        }
                        if ((scanType.Contains("退件登记") || scanType.Contains("拦截件登记")) || (scanType.Contains("问题件扫描") && roadBean.waybillTrackingContent.Contains("退回")))
                        {
                            if (siteName == StoParams.Instance.register_site)
                            {
                                if (roadBeanRegSiteIntercept.scanTime == "")
                                {
                                    roadBeanRegSiteIntercept = roadBean;
                                }

                            }
                        }

                        if (scanType.Contains("入库扫描") && lastUsefulSite.Contains("网点") && dispatchInwareTime == "" && lastUsefulSite != StoParams.Instance.register_site)
                        {
                            dispatchInwareTime = scanTime;
                        }

                        if (scanType.Contains("装车发件") && roadBean.nextStopName.Contains("网点") && depToDispatchSite == "" && arrivalScanTime == "" && roadBean.nextStopName != StoParams.Instance.register_site)
                        {
                            depToDispatchSite = scanTime;
                            lastUsefulSite = roadBean.nextStopName;
                        }
                        if (scanType.Contains("装车发件") && siteName.Contains("网点") && lastUsefulSite != StoParams.Instance.register_site)
                        {
                            if (roadBeanRegSiteIntercept.scanTime != "")
                            {
                                roadSiteDepBean = roadBean;
                            }

                        }

                    }

                    //已做入库的逻辑
                    if (depToDispatchSite != "" && dispatchInwareTime != "")
                    {
                        if (roadBeanRegSiteIntercept.scanTime != "" && roadSiteDepBean.scanTime != "")
                        {
                            TimeSpan tscur = Convert.ToDateTime(roadSiteDepBean.scanTime).Date - Convert.ToDateTime(roadBeanRegSiteIntercept.scanTime).Date;
                            if (tscur.TotalDays >= 7)
                            {
                                resultBean.dutySite = roadSiteDepBean.scanNetworkName;
                                resultBean.delayDays = ((int)tscur.TotalDays).ToString();
                                resultBean.errorType = "彻底延误";
                                resultBean.errorMsg = "彻底延误";

                                return true;
                            }
                        }


                    }

                    //未做入库的逻辑
                    else
                    {
                        for (int i = 0; i < arListRoadMap.Count; i++)
                        {
                            RoadBean roadBean = (RoadBean)arListRoadMap[i];
                            string siteName = roadBean.scanNetworkName;
                            string nextName = roadBean.nextStopName;
                            string scanType = roadBean.scanTypeName;
                            string scanTime = roadBean.scanTime;

                            if (scanType.Contains("卸车到件") && siteName.Contains("网点") && arrivalScanTime == "" && siteName != StoParams.Instance.register_site)
                            {
                                arrivalScanTime = scanTime;

                            }

                            if (scanType.Contains("装车发件") && roadBean.nextStopName.Contains("网点") && depToDispatchSite == "" && arrivalScanTime == "" && roadBean.nextStopName != StoParams.Instance.register_site)
                            {
                                depToDispatchSite = scanTime;

                            }

                            if (scanType.Contains("出仓扫描") && siteName.Contains("网点") && wareOutScanTime == "" && siteName != StoParams.Instance.register_site)
                            {
                                wareOutScanTime = scanTime;
                                wareOutScanSite = siteName;
                            }

                            if (scanType.Contains("快件取出扫描") && siteName.Contains("网点") && siteName != StoParams.Instance.register_site)
                            {
                                wareOutScanTime = scanTime;
                                wareOutScanSite = siteName;
                            }

                            if (scanType.Contains("问题件扫描") && siteName.Contains("网点") && siteName != StoParams.Instance.register_site)
                            {
                                if (wareOutScanTime != "")
                                {
                                    try
                                    {
                                        DateTime dtWareOut = Convert.ToDateTime(wareOutScanTime);
                                        DateTime dtScanProblem = Convert.ToDateTime(scanTime);
                                        TimeSpan ts = dtScanProblem - dtWareOut;
                                        if (dtScanProblem > dtWareOut && ts.TotalDays < 2)
                                        {
                                            dtWareOut = dtScanProblem;
                                            wareOutScanTime = scanTime;
                                        }

                                    }
                                    catch (Exception exx)
                                    {

                                    }
                                }
                            }
                            if (scanType.Contains("退件扫描") && siteName.Contains("网点") && interceptScanTime == "" && siteName != StoParams.Instance.register_site)
                            {
                                interceptScanTime = scanTime;

                            }

                            if (scanType.Contains("装车发件") && siteName.Contains("网点") && siteName != StoParams.Instance.register_site)
                            {
                                if (wareOutScanTime == "")
                                {
                                    wareOutScanTime = arrivalScanTime;
                                    if (wareOutScanTime == "")
                                    {
                                        wareOutScanTime = depToDispatchSite;
                                    }
                                }
                                if (interceptScanTime != "" && wareOutScanTime != "")
                                {
                                    if (resultBean.wayBillNo == "JT2960743864259")
                                    {
                                        logHelp.LogHelper.Instance.writeLog("测试站点:" + StoParams.Instance.register_site + " 4583 行 scanTime=" + scanTime+ " wareOutScanTime="+ wareOutScanTime);
                                    }
                                    TimeSpan ts = Convert.ToDateTime(Convert.ToDateTime(scanTime).ToShortDateString()) - Convert.ToDateTime(Convert.ToDateTime(wareOutScanTime).ToShortDateString());
                                    if (ts.TotalDays >= 7)
                                    {
                                        resultBean.dutySite = siteName;
                                        resultBean.delayDays = ((int)ts.TotalDays).ToString();
                                        resultBean.errorType = "彻底延误";
                                        resultBean.errorMsg = "彻底延误";

                                        return true;

                                    }
                                    else
                                    {
                                        //return false;
                                    }
                                }

                            }


                        }
                    }

                    roadBeanRegSiteIntercept = new RoadBean();

                    for (int i = 0; i < arListRoadMap.Count; i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        string siteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string scanTime = roadBean.scanTime;

                        if ((scanType.Contains("退件登记") || scanType.Contains("拦截件登记")) || (scanType.Contains("问题件扫描") && roadBean.waybillTrackingContent.Contains("退回")))
                        {
                            if (siteName == StoParams.Instance.register_site)
                            {
                                if (roadBeanRegSiteIntercept.scanTime == "")
                                {
                                    roadBeanRegSiteIntercept = roadBean;
                                }

                            }
                        }


                        else if (siteName != "" && siteName != StoParams.Instance.register_site)
                        {

                            if ((scanType.Contains("到件") && roadBeanRegSiteIntercept.scanTime != ""))
                            {
                                if (lastOtherSiteRoadBean.scanTypeName.Contains("发件") || lastOtherSiteRoadBean.scanTypeName.Contains("到件"))
                                {
                                    TimeSpan tsE = Convert.ToDateTime(scanTime).Date - Convert.ToDateTime(lastOtherSiteRoadBean.scanTime).Date;
                                    if (tsE.TotalDays >= 7)
                                    {
                                        resultBean.dutySite = siteName;
                                        resultBean.delayDays = ((int)tsE.TotalDays).ToString();
                                        resultBean.errorType = "彻底延误";
                                        resultBean.errorMsg = "彻底延误";

                                        return true;

                                    }
                                }

                            }

                            if ((scanType.Contains("发件") || scanType.Contains("建包")) && roadBeanRegSiteIntercept.scanTime != "")
                            {
                                if (lastOtherSiteRoadBean.scanTypeName.Contains("发件") || lastOtherSiteRoadBean.scanTypeName.Contains("到件") || lastOtherSiteRoadBean.scanTypeName.Contains("出仓"))
                                {
                                    TimeSpan tsE = Convert.ToDateTime(scanTime).Date - Convert.ToDateTime(lastOtherSiteRoadBean.scanTime).Date;
                                    if (tsE.TotalDays >= 7)
                                    {
                                        resultBean.dutySite = siteName;
                                        resultBean.delayDays = ((int)tsE.TotalDays).ToString();
                                        resultBean.errorType = "彻底延误";
                                        resultBean.errorMsg = "彻底延误";

                                        return true;

                                    }
                                    else if (tsE.TotalDays >= 3)
                                    {
                                        resultBean.dutySite = siteName;
                                        resultBean.delayDays = ((int)tsE.TotalDays).ToString();
                                        resultBean.errorType = "退回延误";
                                        resultBean.errorMsg = "退回延误";

                                        return true;
                                    }
                                }
                                break;
                            }

                            lastUsefulSite = siteName;
                            if (!scanType.Contains("问题件") && !scanType.Contains("退件") && !scanType.Contains("拦截件") && !scanType.Contains("完结"))
                            {
                                lastOtherSiteRoadBean = roadBean;
                            }

                        }




                    }



                }
                catch (Exception ex)
                {

                }
                return res;
            }
            
        }




        private bool isPickoutNoScanProblem(ArrayList arListRoadMap, ResultBean resultBean,
    ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime,
    string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival, string lanshouSite)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();

                RoadBean priorDepBean = new RoadBean();

                RoadBean interCeptBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                string interCeptScanSite = "";
                bool hasArrivalSite = false;
                string siteSendTime = "";
                string firstSite = "";

                Hashtable htInterceptSite = new Hashtable();
                Hashtable htPriorBean = new Hashtable();
                bool nextStopSiteAppear = false;
                Hashtable htProblemScaned = new Hashtable();
                string pickOutScanTime = "";
                string problemScanTime = "";
                Hashtable htNoReasonReject = new Hashtable();
                Hashtable htCurDayProblem = new Hashtable();
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    string dateKey = scanTime.Substring(0,scanTime.IndexOf(' '));

                    if ((scanType.Contains("拦截件登记") || (scanType.Contains("问题件扫描")) && siteName == StoParams.Instance.register_site))
                    {
                        if (pickOutScanTime == "")
                        {
                            return false;
                        }
                        if (interCeptBean.scanTime == "")
                        {
                            interCeptBean = roadBean;
                            continue;
                        }

                    }


                    if (scanType.Contains("问题件扫描")&& siteName!=StoParams.Instance.register_site&&siteName!= lanshouSite)
                    {
                        htCurDayProblem[dateKey] = dateKey;
                    }
                    if (scanType.Contains("快件取出扫描"))
                    {
                        pickOutScanTime = scanTime;

                        if (interCeptBean.scanTime != "")
                        {
                            if (Convert.ToDateTime(pickOutScanTime) > Convert.ToDateTime(interCeptBean.scanTime))
                            {
                                continue;
                            }
                        }

                        if (htCurDayProblem.ContainsKey(dateKey))
                        {
                            continue;
                        }

                        if (i < arListRoadMap.Count - 1)
                        {
                            RoadBean roadBeanNext = (RoadBean)arListRoadMap[i + 1];
                            TimeSpan ts = Convert.ToDateTime(roadBeanNext.scanTime) - Convert.ToDateTime(scanTime);
                            if (ts.TotalDays >= 2)
                            {
                                resultBean.dutySite = siteName;
                                resultBean.delayDays = ts.TotalDays.ToString();
                                resultBean.errorType = "签收未收到延误";
                                resultBean.errorMsg = "签收未收到延误";
                                return true;
                            }
                        }
                        for (int j = i + 1; j < arListRoadMap.Count; j++)
                        {
                            RoadBean roadBeanJ = (RoadBean)arListRoadMap[j];
                            string siteNameJ = roadBeanJ.scanNetworkName;
                            string nextNameJ = roadBeanJ.nextStopName;
                            string scanTypeJ = roadBeanJ.scanTypeName;
                            if (scanTypeJ.Contains("快件取出扫描"))
                            {
                                pickOutScanTime = roadBeanJ.scanTime;

                                if (j < arListRoadMap.Count - 1)
                                {
                                    RoadBean roadBeanNext = (RoadBean)arListRoadMap[j + 1];
                                    TimeSpan ts = Convert.ToDateTime(roadBeanNext.scanTime) - Convert.ToDateTime(roadBeanJ.scanTime);
                                    if (ts.TotalDays >= 2)
                                    {
                                        resultBean.dutySite = siteName;
                                        resultBean.delayDays = ts.TotalDays.ToString();
                                        resultBean.errorType = "签收未收到延误";
                                        resultBean.errorMsg = "签收未收到延误";
                                        return true;
                                    }
                                }


                            }
                        }

                    }
   
  

                }

            }
            catch (Exception ex)
            {

            }
            return res;
        }


        private bool isPickoutNoScanProblemReturnDelay(ArrayList arListRoadMap, ResultBean resultBean,
            ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime,
            string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival,string lanshouSite)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();

                RoadBean priorDepBean = new RoadBean();

                RoadBean interCeptBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                string interCeptScanSite = "";
                bool hasArrivalSite = false;
                string siteSendTime = "";
                string firstSite = "";

                Hashtable htInterceptSite = new Hashtable();
                Hashtable htPriorBean = new Hashtable();
                bool nextStopSiteAppear = false;
                Hashtable htProblemScaned = new Hashtable();
                string pickOutScanTime = "";
                string problemScanTime = "";
                Hashtable htCurDayProblem = new Hashtable();

                Hashtable htNoReasonReject = new Hashtable();

                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    string dateKey = scanTime.Substring(0, scanTime.IndexOf(' '));

                    if ((scanType.Contains("拦截件登记") || (scanType.Contains("问题件扫描")) && siteName == StoParams.Instance.register_site))
                    {
                        if(pickOutScanTime=="")
                        {
                            return false;
                        }
                        if (interCeptBean.scanTime == "")
                        {
                            interCeptBean = roadBean;
                            continue;
                        }

                    }
                    if (scanType.Contains("问题件扫描") && siteName != StoParams.Instance.register_site && siteName != lanshouSite)
                    {
                        htCurDayProblem[dateKey] = dateKey;
                    }
                    if (scanType.Contains("快件取出扫描") )
                    {
                        pickOutScanTime = scanTime;

                        if(interCeptBean.scanTime!="")
                        {
                            if(Convert.ToDateTime(pickOutScanTime)> Convert.ToDateTime(interCeptBean.scanTime))
                            {
                                continue;
                            }
                        }
                        if (htCurDayProblem.ContainsKey(dateKey))
                        {
                            continue;
                        }
                        if (i < arListRoadMap.Count-1)
                        {
                            RoadBean roadBeanNext = (RoadBean)arListRoadMap[i+1];
                            TimeSpan ts = Convert.ToDateTime(roadBeanNext.scanTime) - Convert.ToDateTime(scanTime);
                            if(ts.TotalDays>=2)
                            {
                                resultBean.dutySite = siteName;
                                resultBean.delayDays = ts.TotalDays.ToString();
                                resultBean.errorType = "签收未收到延误";
                                resultBean.errorMsg = "签收未收到延误";
                                return true;
                            }
                            else
                            {
                                if (Convert.ToDateTime(roadBeanNext.scanTime).ToShortDateString()!= Convert.ToDateTime(scanTime).ToShortDateString())
                                {
                                    if (!roadBeanNext.scanTypeName.Contains("问题件扫描"))
                                    {
                                        if(Convert.ToDateTime(roadBean.scanTime).Hour<18)
                                        {
                                            resultBean.dutySite = siteName;
                                            resultBean.delayDays = "1";
                                            resultBean.errorType = "签收未收到延误";
                                            resultBean.errorMsg = "签收未收到延误";
                                            return true;
                                        }

                                        else if(Convert.ToDateTime(roadBeanNext.scanTime).Hour>=10)
                                        {
                                            resultBean.dutySite = siteName;
                                            resultBean.delayDays ="1";
                                            resultBean.errorType = "签收未收到延误";
                                            resultBean.errorMsg = "签收未收到延误";
                                            return true;
                                        }
                                        else if (Convert.ToDateTime(roadBeanNext.scanTime).Hour >= 9&& (Convert.ToDateTime(roadBeanNext.scanTime).Hour<10))
                                        {
                                            if(Convert.ToDateTime(roadBeanNext.scanTime).Minute>30)
                                            {
                                                resultBean.dutySite = siteName;
                                                resultBean.delayDays = "1";
                                                resultBean.errorType = "签收未收到延误";
                                                resultBean.errorMsg = "签收未收到延误";
                                                return true;
                                            }
                                            
                                        }


                                    }

                                    else
                                    {
                                        if (Convert.ToDateTime(roadBean.scanTime).Hour < 18)
                                        {
                                            resultBean.dutySite = siteName;
                                            resultBean.delayDays = UtilityHelp.Instance.getTotalReturnDelayDays(roadBean.scanTime, roadBeanNext.scanTime).ToString();;
                                            resultBean.errorType = "签收未收到延误";
                                            resultBean.errorMsg = "签收未收到延误";
                                            return true;
                                        }

                                        else if (Convert.ToDateTime(roadBeanNext.scanTime).Hour >= 10)
                                        {
                                            resultBean.dutySite = siteName;
                                            resultBean.delayDays = UtilityHelp.Instance.getTotalReturnDelayDays(roadBean.scanTime, roadBeanNext.scanTime).ToString();
                                            resultBean.errorType = "签收未收到延误";
                                            resultBean.errorMsg = "签收未收到延误";
                                            return true;
                                        }
                                        else if (Convert.ToDateTime(roadBeanNext.scanTime).Hour >= 9 && (Convert.ToDateTime(roadBeanNext.scanTime).Hour < 10))
                                        {
                                            if (Convert.ToDateTime(roadBeanNext.scanTime).Minute > 30)
                                            {
                                                resultBean.dutySite = siteName;
                                                resultBean.delayDays = UtilityHelp.Instance.getTotalReturnDelayDays(roadBean.scanTime, roadBeanNext.scanTime).ToString(); 
                                                resultBean.errorType = "签收未收到延误";
                                                resultBean.errorMsg = "签收未收到延误";
                                                return true;
                                            }

                                        }
                                    }
                                }
                                
                            }
                        }
                        for(int j=i+1;j< arListRoadMap.Count;j++)
                        {
                            RoadBean roadBeanJ = (RoadBean)arListRoadMap[j];
                            string siteNameJ = roadBeanJ.scanNetworkName;
                            string nextNameJ = roadBeanJ.nextStopName;
                            string scanTypeJ = roadBeanJ.scanTypeName;
                            if(scanTypeJ.Contains("快件取出扫描"))
                            {
                                pickOutScanTime = roadBeanJ.scanTime;

                                if(j< arListRoadMap.Count-1)
                                {
                                    RoadBean roadBeanNext = (RoadBean)arListRoadMap[j + 1];
                                    TimeSpan ts = Convert.ToDateTime(roadBeanNext.scanTime) - Convert.ToDateTime(roadBeanJ.scanTime);
                                    if (ts.TotalDays >= 2)
                                    {
                                        resultBean.dutySite = siteName;
                                        resultBean.delayDays = ts.TotalDays.ToString();
                                        resultBean.errorType = "签收未收到延误";
                                        resultBean.errorMsg = "签收未收到延误";
                                        return true;
                                    }
                                }
                                

                            }
                        }

                    }
                    if (scanType.Contains("问题件扫描")&& pickOutScanTime!="")
                    {
                       
                        TimeSpan ts = Convert.ToDateTime(Convert.ToDateTime(scanTime).ToShortDateString()) - Convert.ToDateTime(Convert.ToDateTime(pickOutScanTime).ToShortDateString());
                        if(ts.TotalDays==0)
                        {
                            return false;
                        }
                        if (ts.TotalDays>1)
                        {
                            resultBean.dutySite = siteName;
                            resultBean.delayDays = ts.TotalDays.ToString();
                            resultBean.errorType = "签收未收到延误";
                            resultBean.errorMsg = "签收未收到延误";
                            if(ts.TotalDays >=7)
                            {
                                resultBean.errorType = "彻底延误";
                                resultBean.errorMsg = "彻底延误";
                            }

                            if(lanshouSite.Contains("江东"))
                            {
                                resultBean.errorType = "快递柜取出";
                                resultBean.errorMsg = "快递柜取出";
                            }
                            return true;

                        }
                        else if(ts.TotalDays==1)
                        {

                            TimeSpan ts2= Convert.ToDateTime(Convert.ToDateTime(scanTime)) - Convert.ToDateTime(Convert.ToDateTime(pickOutScanTime));
                            if(ts2.TotalHours>16)
                            {
                                resultBean.dutySite = siteName;
                                resultBean.delayDays = ts.TotalDays.ToString();
                                resultBean.errorType = "签收未收到延误";
                                resultBean.errorMsg = "签收未收到延误";
                                if (ts.TotalDays >= 7)
                                {
                                    resultBean.errorType = "彻底延误";
                                    resultBean.errorMsg = "彻底延误";
                                }
                                if (lanshouSite.Contains("江东"))
                                {
                                    resultBean.errorType = "快递柜取出";
                                    resultBean.errorMsg = "快递柜取出";
                                }

                                return true;
                            }
                            if (ts2.TotalHours < 12 && (Convert.ToDateTime(scanTime).Date == Convert.ToDateTime(pickOutScanTime).Date))
                            {
                                return false;
                            }
                            if(Convert.ToDateTime(scanTime).Hour<9&& Convert.ToDateTime(pickOutScanTime).Hour>=18)
                            {
                                return false;
                            }
                            else if (Convert.ToDateTime(scanTime).Hour == 9 && Convert.ToDateTime(pickOutScanTime).Hour >= 18)
                            {
                                if(Convert.ToDateTime(scanTime).Minute<=30)
                                {
                                    return false;
                                }
                                
                            }

                        }
                    }
                    else if(scanType.Contains("问题件扫描") && pickOutScanTime == "")
                    {
                        for(int j=i;j< arListRoadMap.Count; j++)
                        {
                            RoadBean roadBeanJ = (RoadBean)arListRoadMap[j];
                            if(roadBeanJ.scanTypeName.Contains("快件取出扫描"))
                            {
                                if(roadBeanJ.scanNetworkName== siteName)
                                {
                                    TimeSpan ts = Convert.ToDateTime(Convert.ToDateTime(roadBeanJ.scanTime).ToShortDateString()) - Convert.ToDateTime(Convert.ToDateTime(scanTime).ToShortDateString());
                                    if (ts.TotalDays <1)
                                    {
                                        return false;
                                    }
                                
                                }
                            }
                        }
                    }                 

                    }
           
            }
            catch (Exception ex)
            {

            }
            return res;
        }




        /// <summary>
        /// 退回延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isSiteReturnDelayOnlyBaseInterCeptTime(ArrayList arListRoadMap, ResultBean resultBean,Hashtable htAllTaskTime,Hashtable htAllSite
            )
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/
                RoadBean priorDepBean = new RoadBean();

                RoadBean interCeptBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                string interCeptScanSite = "";
                bool hasArrivalSite = false;
                string siteSendTime = "";
                string firstSite = "";

                Hashtable htInterceptSite = new Hashtable();
                Hashtable htPriorBean = new Hashtable();
                bool nextStopSiteAppear = false;
                bool findSenderInterCeptRecord = false;
                int curIndexFind = 0;
                string senderInterCeptTime = "";

                ArrayList arListDirectCenter = new ArrayList();
                Hashtable htCenterDirtect = new Hashtable();
                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if(roadBean.scanTypeName.Contains("退件扫描")&& roadBean.scanNetworkName!=StoParams.Instance.register_site)
                    {
                        break;
                    }
                    //if(roadBean.scanNetworkName.Contains("网点"))
                    {
                        if(roadBean.scanTypeName.Contains("到件") && roadBean.packageNumber!="")
                        {
                            if(!htCenterDirtect.ContainsKey(roadBean.scanNetworkName))
                            {
                                PackageBean pbBean = new PackageBean();
                                pbBean.arrivalpackage = roadBean.packageNumber;
                                htCenterDirtect[roadBean.scanNetworkName] = pbBean;
                            }
                        }
                        else if (roadBean.scanTypeName.Contains("发件") && roadBean.packageNumber != "")
                        {
                            if (!htCenterDirtect.ContainsKey(roadBean.scanNetworkName))
                            {
                                PackageBean pbBean = new PackageBean();
                                pbBean.deppackage = roadBean.packageNumber;
                                htCenterDirtect[roadBean.scanNetworkName] = pbBean;
                                pbBean.depMapIndex = i;
                            }
                            else
                            {
                                PackageBean pbBean = htCenterDirtect[roadBean.scanNetworkName] as PackageBean;
                                pbBean.deppackage = roadBean.packageNumber;
                                pbBean.depMapIndex = i;
                            }
                        }
                    }

                }

                foreach(DictionaryEntry de in htCenterDirtect)
                {
                    PackageBean pbBean = (PackageBean)de.Value;
                    if(pbBean.arrivalpackage==pbBean.deppackage)
                    {
                        arListDirectCenter.Add(de.Key.ToString());
                    }
                }

                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;


                    if ((scanType.Contains("退件登记") &&siteName == StoParams.Instance.register_site))
                    {
                        curIndex = i + 1;
                        interCeptBean = roadBean;
                        findSenderInterCeptRecord = true;
                        curIndexFind = i + 1;
                        senderInterCeptTime = scanTime;

                        if(arListDirectCenter.Count>0)
                        {
                            string fristNetWork = arListDirectCenter[0].ToString();
                            bool bingoDirect = false;
                            for (int j = i + 1; j < arListRoadMap.Count; j++)
                            {
                                
                                RoadBean roadBeanJ = (RoadBean)arListRoadMap[j];
                                if (arListDirectCenter.Contains(roadBeanJ.scanNetworkName) && roadBeanJ.scanNetworkName.Length > 1)
                                {
                                    bingoDirect = true;
                                }
                                if(bingoDirect)
                                {
                                    if(roadBeanJ.scanNetworkName!=StoParams.Instance.register_site&&arListDirectCenter.Contains(roadBeanJ.scanNetworkName)
                                        && roadBeanJ.scanTypeName.Contains("发件")&&!arListDirectCenter.Contains(roadBeanJ.nextStopName))
                                    {
                                        senderInterCeptTime = roadBeanJ.scanTime;
                                        if (htAllSite.ContainsKey(roadBeanJ.nextStopName)&& roadBeanJ.nextStopName.Contains("网点"))
                                        {
                                            DbgBean dbgSite = htAllSite[roadBeanJ.nextStopName] as DbgBean;
                                            if(Utility.isTimeRight(dbgSite.actualArrivalTime))
                                            {
                                                senderInterCeptTime = dbgSite.actualArrivalTime.ToString();
                                            }
                                            
                                        }
                                       
                                        break;
                                    }
                                }
                            }
                        }
                        
                        
                        break;

                    }

                    if ((scanType.Contains("问题件") && siteName == StoParams.Instance.register_site))
                    {
                        if(roadBean.waybillTrackingContent.Contains("退回"))
                        {
                            curIndex = i + 1;
                            interCeptBean = roadBean;
                            findSenderInterCeptRecord = true;
                            curIndexFind = i + 1;
                            senderInterCeptTime = scanTime;

                            if (arListDirectCenter.Count > 0)
                            {
                                string fristNetWork = arListDirectCenter[0].ToString();
                                bool bingoDirect = false;
                                for (int j = i + 1; j < arListRoadMap.Count; j++)
                                {
                                    
                                    RoadBean roadBeanJ = (RoadBean)arListRoadMap[j];
                                    if (arListDirectCenter.Contains(roadBeanJ.scanNetworkName) && roadBeanJ.scanNetworkName.Length > 1)
                                    {
                                        bingoDirect = true;
                                    }
                                    if (bingoDirect)
                                    {
                                        if (roadBeanJ.scanNetworkName != StoParams.Instance.register_site && arListDirectCenter.Contains(roadBeanJ.scanNetworkName) && roadBeanJ.scanTypeName.Contains("发件"))
                                        {
                                            senderInterCeptTime = roadBeanJ.scanTime;
                                            if (htAllSite.ContainsKey(roadBeanJ.nextStopName) && roadBeanJ.nextStopName.Contains("网点"))
                                            {
                                                DbgBean dbgSite = htAllSite[roadBeanJ.nextStopName] as DbgBean;
                                                if (Utility.isTimeRight(dbgSite.actualArrivalTime))
                                                {
                                                    senderInterCeptTime = dbgSite.actualArrivalTime.ToString();
                                                }

                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            break;
                        }
                        

                    }



                }
                if (!findSenderInterCeptRecord)
                {
                    return false;
                }
                string returnTime = "";
                string returSite = "";
                for(int i=curIndex;i<arListRoadMap.Count;i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if(siteName!=StoParams.Instance.register_site&& scanType.Contains("退件"))
                    {
                        returnTime = scanTime;
                        returSite = siteName;
                    }
                    if(scanType.Contains("发件")&& siteName== returSite)
                    {
                        if(Convert.ToDateTime(scanTime).ToShortDateString()!= Convert.ToDateTime(returnTime).ToShortDateString())
                        {
                            if(Convert.ToDateTime(scanTime)> Convert.ToDateTime(returnTime))
                            {
                                returnTime = scanTime;
                            }
                        }
                    }
                }

                if(returnTime!="")
                {
                    if(htAllTaskTime.ContainsKey(returSite))
                    {
                        DbgBean dbg = htAllTaskTime[returSite] as DbgBean;
                        if(dbg.plannedArrivalTime > Convert.ToDateTime(senderInterCeptTime))
                        {
                            senderInterCeptTime = dbg.plannedArrivalTime.ToString();
                        }
                    }
                    TimeSpan ts = Convert.ToDateTime(returnTime) - Convert.ToDateTime(senderInterCeptTime);
                    if(ts.TotalDays>1&& (Convert.ToDateTime(returnTime).ToShortDateString()!= Convert.ToDateTime(senderInterCeptTime).AddDays(1).ToShortDateString()))
                    {
                        res = true;
                        resultBean.dutySite = returSite;
                        resultBean.errorType = "退回延误";
                        resultBean.delayDays = (((int)ts.TotalDays) - 1).ToString();
                        if(resultBean.delayDays=="0")
                        {
                            resultBean.delayDays = "1";
                        }

                        return true;
                    }
                }

   
                /*string terMinalLeaver = "";
                for (int i = curIndex; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (nextName != "" && scanType.Contains("发件")&& siteName== priorDepBean.nextStopName)
                    {
                        bool isLastSend = true;
                        if(i< arListRoadMap.Count-1)
                        {
                            for (int j = i + 1; j < arListRoadMap.Count; j++)
                            {
                                RoadBean roadBeanJ = (RoadBean)arListRoadMap[j];
                                if (roadBeanJ.scanTypeName.Contains("发件"))
                                {
                                    isLastSend = false;
                                }
                            }
                        }
                       
                        if(!isLastSend)
                        {
                            terMinalLeaver = scanTime;
                            break;

                        }
                        
                    }
                }

                if (terMinalLeaver == "")
                {
                    for (int i = curIndex; i < arListRoadMap.Count; i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        string siteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string scanTime = roadBean.scanTime;
                        if (scanType.Contains("到件") && siteName == priorDepBean.scanNetworkName)
                        {
                            terMinalLeaver = scanTime;
                            break;
                        }
                    }
                    if (terMinalLeaver == "")
                    {
                        terMinalLeaver = System.DateTime.Now.ToString();
                    }

                }
                if(regInterCeptTime!=""&& terMinalLeaver!="")
                {
                    DateTime dtRegInterScan = Convert.ToDateTime(Convert.ToDateTime(regInterCeptTime).ToShortDateString());
                    DateTime dtrMinalLeaver = Convert.ToDateTime(Convert.ToDateTime(terMinalLeaver).ToShortDateString());
                    TimeSpan ts = dtrMinalLeaver - dtRegInterScan;
                    if(ts.TotalDays<=1)
                    {
                        return false;
                    }
                    res = true;
                    resultBean.dutySite = interCeptScanSite;
                    resultBean.errorType = "退回延误";
                    resultBean.delayDays = (Convert.ToInt32(ts.TotalDays.ToString()) - 1).ToString();
                   
                    return true;


                }*/




            }
            catch (Exception ex)
            {

            }
            return res;
        }



        /// <summary>
        /// 退回延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isCenterOrSiteReturnDelay(ArrayList arListRoadMap, ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, Hashtable htAllTaskTime, string terminalDepTime, ArrayList arListAllTaskCenters, string dispatchSite, string dispatchSiteArrival)
        {
            bool res = false;
            string shouldDepTime = "";
            try
            {

                string jsSite = "";
                string lastCenter = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";
                string lastCenterActArriveTime = "";

                Hashtable htCarDelay = new Hashtable();
                /*foreach (string strSiteName in arListAllSite)
                {
                    if (strSiteName.ToString().Contains("转运中心")&& htAllTaskTime.ContainsKey(strSiteName))
                    {
                        arListAllTaskCenters.Add(strSiteName);
                    }
                }*/
                RoadBean priorDepBean = new RoadBean();

                RoadBean interCeptBean = new RoadBean();
                string regInterCeptTime = "";
                int curIndex = 0;
                string interCeptScanSite = "";
                bool hasArrivalSite = false;
                string siteSendTime = "";
                string firstSite = "";

                Hashtable htInterceptSite = new Hashtable();
                Hashtable htPriorBean = new Hashtable();
                bool nextStopSiteAppear = false;
                string regsiteRegTime = "";

                Hashtable htInterceptSiteTime = new Hashtable();

                for (int i = 0; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;



                    if ((scanType.Contains("拦截件登记") || scanType.Contains("拦截件扫描")) && siteName == StoParams.Instance.register_site)
                    {
                        regsiteRegTime = scanTime;

                    }



                    if ((scanType.Contains("拦截件登记")|| scanType.Contains("拦截件扫描")) && 
                        (siteName!=StoParams.Instance.register_site&& !roadBean.waybillTrackingContent.Contains("平台在线")))
                    {
                        if(interCeptBean.scanTime=="")
                        {
                            interCeptBean = roadBean;
                            if(!hasArrivalSite)
                            {
                                interCeptBean.isValidIntercept = true;
                                nextStopSiteAppear = false;
                            }
                        }
                        
                    }
                    if (nextName != "" && scanType.Contains("发件") && regInterCeptTime == "")
                    {
                        priorDepBean = roadBean;
                    }

                    if (siteName.Contains("网点") && (scanType.Contains("到件")|| scanType.Contains("入库")) && siteName != StoParams.Instance.register_site)
                    {
                        hasArrivalSite = true;
                    }


                    if (siteName.Contains("网点") && (scanType.Contains("发件")) && siteName != StoParams.Instance.register_site)
                    {
                        siteSendTime = scanTime;
                        firstSite = siteName;
                    }

                    if(interCeptBean.scanTime != ""&& siteName != StoParams.Instance.register_site&& nextStopSiteAppear==false&& roadBean.scanTypeName.Contains("到件"))
                    {
                        nextStopSiteAppear = true;

                        int curInterCeptIndex = i;
                        if (!htInterceptSite.ContainsKey(siteName))
                        {
                            bool hasCurSiteDoneIntercept = false;
                            for(int j=i;j < arListRoadMap.Count; j++)
                            {
                                RoadBean roadBeanJ = (RoadBean)arListRoadMap[j];
                                if(roadBeanJ.scanTypeName.Contains("拦截件扫描")&& roadBeanJ.scanNetworkName== siteName)
                                {
                                    hasCurSiteDoneIntercept = true;
                                    curInterCeptIndex = j;
                                    break;
                                }
                            }
                            if(hasCurSiteDoneIntercept)
                            {
                                curIndex = curInterCeptIndex;
                                if(!htInterceptSiteTime.ContainsKey(siteName))
                                {
                                    htInterceptSiteTime[siteName] = roadBean.scanTime;
                                }
                                //regInterCeptTime = roadBean.scanTime;
                                //interCeptScanSite = roadBean.scanNetworkName;
                                htInterceptSite[siteName] = curInterCeptIndex.ToString();
                                
                                RoadBean rb = new RoadBean();
                                rb.scanNetworkName = priorDepBean.scanNetworkName;
                                rb.scanTime = priorDepBean.scanTime;
                                rb.nextStopName = priorDepBean.nextStopName;
                                if (rb.nextStopName == siteName)
                                {
                                    htPriorBean[siteName] = rb;
                                }
                            }

                            

                        }
                    }
                    if (roadBean.scanTypeName != null && (roadBean.scanTypeName == "拦截件扫描"&& roadBean.scanNetworkName!=StoParams.Instance.register_site))
                    {
                        if(!htInterceptSite.ContainsKey(siteName))
                        {
                            curIndex = i;
                            if (!htInterceptSiteTime.ContainsKey(siteName))
                            {
                                htInterceptSiteTime[siteName] = roadBean.scanTime;
                            }
                            //regInterCeptTime = roadBean.scanTime;
                            interCeptScanSite = roadBean.scanNetworkName;
                            htInterceptSite[siteName] = i.ToString();

                            RoadBean rb = new RoadBean();
                            rb.scanNetworkName = priorDepBean.scanNetworkName;
                            rb.scanTime = priorDepBean.scanTime;
                            rb.nextStopName = priorDepBean.nextStopName;
                            if (rb.nextStopName == siteName)
                            {
                                htPriorBean[siteName] = rb;
                            }

                        }



                    }
                }
                if (htInterceptSiteTime.Count==0)
                {
                    return false;
                }

                

                foreach(string site in htInterceptSite.Keys)
                {
                    string curRow = htInterceptSite[site].ToString();
                    RoadBean curBean= (RoadBean)arListRoadMap[Convert.ToInt32(curRow)];

                    if(!site.Contains("网点"))
                    {
                        for (int m = Convert.ToInt32(curRow) + 1; m < arListRoadMap.Count; m++)
                        {
                            RoadBean roadBean = (RoadBean)arListRoadMap[m];
                            if (roadBean.scanNetworkName == curBean.scanNetworkName && roadBean.scanTypeName.Contains("发件"))
                            {
                                string planArrivalTime = curBean.scanTime;
                                if (htAllTaskTime.ContainsKey(site))
                                {
                                    DbgBean dbg = htAllTaskTime[site] as DbgBean;
                                    if (Utility.isTimeRight(dbg.plannedArrivalTime))
                                    {
                                        planArrivalTime = dbg.plannedArrivalTime.ToString();
                                    }
                                    else
                                    {
                                        if (htSiteTime.ContainsKey(site))
                                        {
                                            dbg = htSiteTime[site] as DbgBean;
                                            planArrivalTime = dbg.actualArrivalTime.ToString();
                                        }
                                    }
                                        
                                }
                                else
                                {
                                    if(htSiteTime.ContainsKey(site))
                                    {
                                        DbgBean dbg = htSiteTime[site] as DbgBean;
                                        planArrivalTime = dbg.actualArrivalTime.ToString();
                                    }
                                }


                                if (roadBean.scanTime!=""  && roadBean.plannedDepTime=="")
                                {
                                    roadBean.plannedDepTime = roadBean.scanTime;
                                }
                                regInterCeptTime = htInterceptSiteTime[site].ToString();
                                if (UtilityHelp.Instance.isReturnDelay(regInterCeptTime, roadBean.plannedDepTime, resultBean, site))
                                {
                                    //if (!UtilityHelp.Instance.isContainZCFJNext(m, roadBean.scanNetworkName, arListRoadMap))
                                    {
                                        if(!resultBean.errorType.Contains("彻底"))
                                        {
                                            resultBean.errorType = "退回延误(按拦截时间)";
                                        }
                                            
                                        return true;
                                    }
                                }
                                else if (UtilityHelp.Instance.isReturnDelay(planArrivalTime, roadBean.plannedDepTime, resultBean, site))
                                {
                                    //if(!UtilityHelp.Instance.isContainZCFJNext(m, roadBean.scanNetworkName, arListRoadMap))
                                    {
                                        if (!resultBean.errorType.Contains("彻底"))
                                        {
                                            resultBean.errorType = "退回延误(按计划到件)";
                                            return true;
                                        }
                                            
                                    }
                                    
                                }
                                /*else if(UtilityHelp.Instance.isReturnDelay(regInterCeptTime, roadBean.plannedDepTime, resultBean, site))
                                {
                                    if (!UtilityHelp.Instance.isContainZCFJNext(m, roadBean.scanNetworkName, arListRoadMap))
                                    {
                                        resultBean.errorType = "退回延误(按拦截时间)";
                                        return true;
                                    }
                                }*/
                                else
                                {
                                    return false;
                                    
                                }
                            }
                            if ((roadBean.scanTypeName.Contains("到件") || roadBean.scanTypeName.Contains("建包") || roadBean.scanTypeName.Contains("发件")) &&
                                    roadBean.scanNetworkName != curBean.scanNetworkName)
                            {
                                string nextTime = roadBean.scanTime;
                                if(roadBean.plannedDepTime!="")
                                {
                                    try
                                    {
                                        TimeSpan tsc = Convert.ToDateTime(roadBean.plannedDepTime) - Convert.ToDateTime(nextTime);
                                        if(tsc.TotalHours>0)
                                        {
                                            nextTime = roadBean.plannedDepTime;
                                        }
                                    }
                                    catch(Exception ex)
                                    {

                                    }

                                }
                                if (UtilityHelp.Instance.isReturnDelay(curBean.scanTime, nextTime, resultBean, site))
                                {
                                    return true;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            if ((roadBean.scanNetworkName != curBean.scanNetworkName) && (roadBean.scanTypeName.Contains("拦截件") || roadBean.scanTypeName.Contains("问题件")))
                            {
                                for (int cm = Convert.ToInt32(curRow) + 1; cm < arListRoadMap.Count; cm++)
                                {
                                    RoadBean croad = (RoadBean)arListRoadMap[cm];
                                    if(croad.scanNetworkName== curBean.scanNetworkName&& croad.scanTypeName.Contains("发件"))
                                    {
                                        if (UtilityHelp.Instance.isReturnDelay(curBean.scanTime, croad.plannedDepTime, resultBean, site))
                                        {
                                            if (!UtilityHelp.Instance.isContainZCFJNext(m, croad.scanNetworkName, arListRoadMap))
                                            {
                                                return true;
                                            }

                                        }
                                    }
                                }
                            }
                        }

                    }
                    else
                    {
                        string inwarhouseTime = "";
                        string depTime = "";
                        string siteReturnDepTime = "";
                        string packageSignOutScantime = "";
                        string lastUseFulScanSite = "";
                        for (int m = 0; m < arListRoadMap.Count; m++)
                        {
                            RoadBean bean = (RoadBean)arListRoadMap[m];
                            if(bean.scanNetworkName!=""&& bean.scanNetworkName!=StoParams.Instance.register_site)
                            {
                                lastUseFulScanSite = bean.scanNetworkName;
                            }
                            if(bean.scanNetworkName=="")
                            {
                                bean.scanNetworkName = lastUseFulScanSite;
                            }
                            if(bean.scanTypeName.Contains("入库")&& bean.scanNetworkName== site)
                            {
                                inwarhouseTime = bean.scanTime;
                            }

                            if (bean.scanTypeName.Contains("快件取出扫描") && bean.scanNetworkName == site)
                            {
                                packageSignOutScantime = bean.scanTime;
                                for(int j=m;j< arListRoadMap.Count; j++)
                                {
                                    RoadBean beanNext = (RoadBean)arListRoadMap[j];
                                    if (beanNext.scanNetworkName==site)
                                    {
                                        string nextScanTime = beanNext.scanTime;
                                        DateTime dtNext = Convert.ToDateTime(nextScanTime);
                                        DateTime dtOut = Convert.ToDateTime(bean.scanTime);
                                        if(dtOut.ToShortDateString()!= dtNext.ToShortDateString())
                                        {
                                            inwarhouseTime = packageSignOutScantime;
                                            break;
                                        }
                                    }
                                }
                                
                            }

                            if (bean.scanTypeName.Contains("发件") && bean.nextStopName == site)
                            {
                                depTime= bean.scanTime;
                            }

                            if (bean.scanTypeName.Contains("发件") && bean.scanNetworkName == site&& siteReturnDepTime=="")
                            {
                                siteReturnDepTime = bean.scanTime;
                            }

                        }
                        if(siteReturnDepTime=="")
                        {
                            for (int m = 0; m < arListRoadMap.Count; m++)
                            {
                                RoadBean bean = (RoadBean)arListRoadMap[m];
                                if (bean.scanNetworkName == site)
                                {
                                    siteReturnDepTime = bean.scanTime;
                                }
                                

                            }
                        }
                        string latestArrivalTime = "";
                        if(htPriorBean.ContainsKey(site))
                        {
                            RoadBean curSBean = htPriorBean[site] as RoadBean;
                            string nextSite = curSBean.nextStopName;
                            lastCenter = curSBean.scanNetworkName;
                            ArrayList arListEffi = new ArrayList();
                            if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(curSBean.scanNetworkName))
                            {
                                Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[curSBean.scanNetworkName] as Hashtable;
                                if (ht.ContainsKey(nextSite))
                                {
                                    arListEffi = ht[nextSite] as ArrayList;
                                }
                            }

                            if (arListEffi.Count > 0)
                            {
                                latestArrivalTime = UtilityHelp.Instance.getMostRecentArrivaTime(Convert.ToDateTime(priorDepBean.scanTime), arListEffi);
                            }
                            else
                            {
                                latestArrivalTime = Convert.ToDateTime(Convert.ToDateTime(priorDepBean.scanTime).AddDays(1)).ToString();
                            }
                        }
                        
                       
                        //if (priorDepBean.nextStopName.Contains("网点") || priorDepBean.nextStopName.Contains("集散"))
                        {
                            

                            if(inwarhouseTime!=""&&packageSignOutScantime!="")
                            {
                                inwarhouseTime = packageSignOutScantime;
                                DateTime dtRegInterScan = Convert.ToDateTime(Convert.ToDateTime(curBean.scanTime).ToShortDateString());
                                DateTime dttInWare = Convert.ToDateTime(Convert.ToDateTime(inwarhouseTime).ToShortDateString());
                                if(dttInWare== dtRegInterScan)
                                {
                                    return false;
                                }
                                if(latestArrivalTime!="")
                                {
                                    DateTime dtLatestArrival = Convert.ToDateTime(Convert.ToDateTime(latestArrivalTime).ToShortDateString());
                                    /*if(dtLatestArrival>= dttInWare)
                                    {
                                        return false;
                                    }
                                    else
                                    {
                                        
                                    }*/
                                    string interceptTime = curBean.scanTime;
                                    if (regsiteRegTime != "")
                                    {
                                        if(Convert.ToDateTime(regsiteRegTime) <Convert.ToDateTime(interceptTime))
                                        {
                                            interceptTime = regsiteRegTime;
                                        }

                                    }
                                    if (interceptTime != "" && siteReturnDepTime != "")
                                    {
                                        DateTime dtReturn = Convert.ToDateTime(siteReturnDepTime);
                                        DateTime dtInterctpt = Convert.ToDateTime(interceptTime);
                                        TimeSpan ts = dtReturn - dtInterctpt;
                                        if (ts.TotalDays > 1)
                                        {
                                            interceptTime = siteReturnDepTime;
                                        }

                                    }
                                    //原来用的是入仓实际，现在改为站点发出时间
                                    if (UtilityHelp.Instance.isReturnDelay(interceptTime, siteReturnDepTime, resultBean, site))
                                    {
                                        return true;
                                    }
                                }
                            }
                            else
                            {
                              
                                if (regsiteRegTime != "")
                                {
                                    regInterCeptTime = htInterceptSiteTime[site].ToString();
                                    if (Convert.ToDateTime(regsiteRegTime) < Convert.ToDateTime(regInterCeptTime))
                                    {
                                        regInterCeptTime = regsiteRegTime;
                                    }

                                }
                                

                                if (regInterCeptTime!=""&& siteReturnDepTime!="")
                                {
                                    DateTime dtReturn = Convert.ToDateTime(siteReturnDepTime);
                                    DateTime dtInterctpt = Convert.ToDateTime(regInterCeptTime);
                                    TimeSpan ts = dtReturn.Date - dtInterctpt.Date;
                                    if (ts.TotalDays > 1)
                                    {
                                        resultBean.dutySite = interCeptScanSite;
                                        resultBean.errorType = "退回延误";
                                        resultBean.delayDays = ((int)(ts.TotalDays) - 1).ToString();
                                        return true;
                                    }
                                }
                                /*if(latestArrivalTime=="")
                                {
                                    latestArrivalTime = depTime;
                                }


                                if(latestArrivalTime != "")
                                {
                                    string interceptTime = curBean.scanTime;
                                    if(interceptTime!=""&&siteReturnDepTime!="")
                                    {
                                        DateTime dtReturn = Convert.ToDateTime(siteReturnDepTime);
                                        DateTime dtInterctpt = Convert.ToDateTime(interceptTime);
                                        TimeSpan ts = dtReturn - dtInterctpt;
                                        if(ts.TotalDays>1)
                                        {
                                            interceptTime = siteReturnDepTime;
                                        }

                                    }
                                    if (UtilityHelp.Instance.isReturnDelay(interceptTime, latestArrivalTime, resultBean, site))
                                    {
                                        return true;
                                    }
                                }*/
                            }


                          
                        }

                     
                    }//网点退回
                    
                }

                if(interCeptBean.scanTime!="")
                {
                    if(interCeptBean.isValidIntercept)
                    {
                        if (UtilityHelp.Instance.isReturnDelay(interCeptBean.scanTime, siteSendTime, resultBean, firstSite))
                        {
                            return true;
                        }
                    }
                }
                /*string terMinalLeaver = "";
                for (int i = curIndex; i < arListRoadMap.Count; i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if (nextName != "" && scanType.Contains("发件")&& siteName== priorDepBean.nextStopName)
                    {
                        bool isLastSend = true;
                        if(i< arListRoadMap.Count-1)
                        {
                            for (int j = i + 1; j < arListRoadMap.Count; j++)
                            {
                                RoadBean roadBeanJ = (RoadBean)arListRoadMap[j];
                                if (roadBeanJ.scanTypeName.Contains("发件"))
                                {
                                    isLastSend = false;
                                }
                            }
                        }
                       
                        if(!isLastSend)
                        {
                            terMinalLeaver = scanTime;
                            break;

                        }
                        
                    }
                }

                if (terMinalLeaver == "")
                {
                    for (int i = curIndex; i < arListRoadMap.Count; i++)
                    {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        string siteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string scanTime = roadBean.scanTime;
                        if (scanType.Contains("到件") && siteName == priorDepBean.scanNetworkName)
                        {
                            terMinalLeaver = scanTime;
                            break;
                        }
                    }
                    if (terMinalLeaver == "")
                    {
                        terMinalLeaver = System.DateTime.Now.ToString();
                    }

                }
                if(regInterCeptTime!=""&& terMinalLeaver!="")
                {
                    DateTime dtRegInterScan = Convert.ToDateTime(Convert.ToDateTime(regInterCeptTime).ToShortDateString());
                    DateTime dtrMinalLeaver = Convert.ToDateTime(Convert.ToDateTime(terMinalLeaver).ToShortDateString());
                    TimeSpan ts = dtrMinalLeaver - dtRegInterScan;
                    if(ts.TotalDays<=1)
                    {
                        return false;
                    }
                    res = true;
                    resultBean.dutySite = interCeptScanSite;
                    resultBean.errorType = "退回延误";
                    resultBean.delayDays = (Convert.ToInt32(ts.TotalDays.ToString()) - 1).ToString();
                   
                    return true;


                }*/




            }
            catch (Exception ex)
            {

            }
            return res;
        }


        public string getNextCenterArrivalTime(ArrayList arListNextStop, DateTime dtDepTime)
        {
            string nextStopTime = "";
            try
            {
                MainLineTimeBean planBean = new MainLineTimeBean();
                MainLineTimeBean shouldBean = new MainLineTimeBean();
                string dtTime = dtDepTime.ToShortTimeString().ToString();
                double totalHours = 100;
                MainLineTimeBean findLineBean = new MainLineTimeBean();
                foreach (MainLineTimeBean mainLineBean in arListNextStop)
                {  
                    if(UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(dtDepTime.ToString(), mainLineBean.dtEffi))
                    {
                        continue;
                    }                  
                    string mainLineDepTime = mainLineBean.plannedDepartureTime;
                    if(Convert.ToDateTime(dtTime)<= Convert.ToDateTime(mainLineDepTime))
                    {
                        TimeSpan ts = Convert.ToDateTime(mainLineDepTime) - Convert.ToDateTime(dtTime);
                        if(ts.TotalHours< totalHours)
                        {
                            findLineBean = mainLineBean;
                            totalHours = ts.TotalHours;
                        }
                    }

                }

                nextStopTime = findLineBean.plannedArrivalNextStopTime;
                int planBeanHour = UtilityHelp.Instance.getHour(nextStopTime);
                int spanDays = 0;
                if (planBeanHour< dtDepTime.Hour)
                {
                    spanDays = 1;
                   
                }

                nextStopTime = dtDepTime.Date.AddDays(spanDays).ToString("yyyy-MM-dd") + " " + nextStopTime;




            }
            catch (Exception ex)
            {

            }
            return nextStopTime;
        }


        public bool isNextSHZXTimeSame(ArrayList arListNextStop,DateTime dtPlanDepTime,DateTime dtShouldDep)
        {
            bool isNextZXTimeSame = false;
            try
            {
                MainLineTimeBean planBean = new MainLineTimeBean();
                MainLineTimeBean shouldBean= new MainLineTimeBean();
                if (dtPlanDepTime.Date== dtShouldDep.Date)
                {
                    foreach(MainLineTimeBean mainLineBean in arListNextStop)
                    {
                        if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(dtPlanDepTime.ToString(), mainLineBean.dtEffi))
                        {
                            continue;
                        }

                        if (mainLineBean.latestSHZXTime!="")
                        {
                            if(Convert.ToDateTime(mainLineBean.plannedDepartureTime).Hour== dtPlanDepTime.Hour
                                && Convert.ToDateTime(mainLineBean.plannedDepartureTime).Minute== dtPlanDepTime.Minute)
                            {
                                planBean.latestSHZXTime = mainLineBean.latestSHZXTime;
                            }
                            if (Convert.ToDateTime(mainLineBean.plannedDepartureTime).Hour == dtShouldDep.Hour
                                && Convert.ToDateTime(mainLineBean.plannedDepartureTime).Minute == dtShouldDep.Minute)
                            {
                                shouldBean.latestSHZXTime = mainLineBean.latestSHZXTime;
                            }
                        }
                    }
                    if(planBean.latestSHZXTime!=""&& shouldBean.latestSHZXTime!="")
                    {
                        if(planBean.latestSHZXTime== shouldBean.latestSHZXTime)
                        {
                            isNextZXTimeSame = true;
                        }
                    }
                }

                else
                {
                    foreach (MainLineTimeBean mainLineBean in arListNextStop)
                    {
                        if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(dtPlanDepTime.ToString(), mainLineBean.dtEffi))
                        {
                            continue;
                        }

                        if (mainLineBean.latestSHZXTime != "")
                        {
                            if (Convert.ToDateTime(mainLineBean.plannedDepartureTime).Hour == dtPlanDepTime.Hour
                                && Convert.ToDateTime(mainLineBean.plannedDepartureTime).Minute == dtPlanDepTime.Minute)
                            {
                                planBean.latestSHZXTime = mainLineBean.latestSHZXTime;
                            }
                            if (Convert.ToDateTime(mainLineBean.plannedDepartureTime).Hour == dtShouldDep.Hour
                                && Convert.ToDateTime(mainLineBean.plannedDepartureTime).Minute == dtShouldDep.Minute)
                            {
                                shouldBean.latestSHZXTime = mainLineBean.latestSHZXTime;
                            }
                        }
                    }
                    if (planBean.latestSHZXTime != "" && shouldBean.latestSHZXTime != "")
                    {
                        int planBeanHour = UtilityHelp.Instance.getHour(planBean.latestSHZXTime);
                        int spanDays = 0;
                        if(planBeanHour< dtPlanDepTime.Hour)
                        {
                            spanDays = 1;
                        }
                        string planLatestSHZXTime = dtPlanDepTime.Date.AddDays(spanDays).ToString("yyyy-MM-dd") + " " + planBean.latestSHZXTime;

                        spanDays = 0;
                        int shouldBeanHour = UtilityHelp.Instance.getHour(shouldBean.latestSHZXTime);
                        if (shouldBeanHour < dtShouldDep.Hour)
                        {
                            spanDays = 1;
                        }
                        string shouldLatestSHZXTime = dtShouldDep.Date.AddDays(spanDays).ToString("yyyy-MM-dd") + " " + shouldBean.latestSHZXTime;

                        if (planLatestSHZXTime == shouldLatestSHZXTime)
                        {
                            isNextZXTimeSame = true;
                        }
                    }
                }
                
            }
            catch(Exception ex)
            {

            }
            return isNextZXTimeSame;
        }
        public bool isReallyLateIfUsingRightPlan(ArrayList arListAllSite, string curSite, string planArrivalSiteConduct, string terminalDepTime,string dispatchSite, string dispatchArrival,out string planArrivalDispatchSite)
        {
            bool res = false;
            planArrivalDispatchSite = "";
            try
            {
                string planArriValDate = planArrivalSiteConduct.Substring(0, planArrivalSiteConduct.IndexOf(' '));
                string planArriValNextSiteDate = "";
                int index = arListAllSite.IndexOf(curSite);
                string nextSite = "";


                

                for (int i = index; i < arListAllSite.Count - 1; i++)
                {
                    curSite = arListAllSite[i].ToString();
                    nextSite = arListAllSite[i + 1].ToString();
                    if (nextSite.Contains("网点"))
                    {
                        break;
                    }
                    planArrivalSiteConduct = getNextSiteArrivalTime(curSite, planArrivalSiteConduct, nextSite);
                    //planArrivalSiteConduct = Convert.ToDateTime(planArrivalSiteConduct).AddHours(1).ToString();

                }
                bool isContainTwoNetSite = false;
                int disPatchSiteIndex = 0;
                if(arListAllSite.Contains(dispatchSite))
                {
                    disPatchSiteIndex = arListAllSite.LastIndexOf(dispatchSite);
                }
                if(disPatchSiteIndex>0)
                {
                    string priorSite = arListAllSite[disPatchSiteIndex - 1].ToString();
                    if(priorSite.Contains("网点"))
                    {
                        isContainTwoNetSite = true;
                    }
                }
                if(isContainTwoNetSite)
                {
                    nextSite = dispatchSite;
                }
                planArriValNextSiteDate = planArrivalSiteConduct.Substring(0, planArrivalSiteConduct.IndexOf(' '));
                
                ArrayList arListEffi = new ArrayList();
                if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(curSite))
                {
                    Hashtable htEffi = LoadBasicHelper.Instance.m_ht_sh_effi[curSite] as Hashtable;
                    if (htEffi.ContainsKey(nextSite))
                    {
                        arListEffi = htEffi[nextSite] as ArrayList;
                       
                    }
                }
                string latestTime = "12:00";
                if (arListEffi.Count==0)
                {
                    arListEffi = LoadBasicHelper.Instance.getDispatchSite(nextSite);                    
                }
                if (arListEffi.Count > 0)
                {
                    latestTime = UtilityHelp.Instance.getLastDispatchSiteArrival(arListEffi, planArrivalSiteConduct.ToString());
                }
                UtilityHelp.Instance.getFirstPlanDepTime(Convert.ToDateTime(planArrivalSiteConduct.ToString()), arListEffi, out planArrivalDispatchSite);
                string jsArrivalConductTime = planArrivalSiteConduct.Substring(planArrivalSiteConduct.IndexOf(' ')).Trim();
                if (Convert.ToDateTime(jsArrivalConductTime) > Convert.ToDateTime(latestTime))
                {
                    res = true;
                    if(Convert.ToDateTime(planArrivalDispatchSite).Date<Convert.ToDateTime(dispatchArrival).Date)
                    {
                        res = false;
                    }
                }
                else
                {
                    if(Convert.ToDateTime(planArriValDate) < Convert.ToDateTime(planArriValNextSiteDate))
                    {
                        res = true;
                    }
                }




            }
            catch(Exception ex)
            {

            }
            return res;

        }

        private string getMainLineArrivlTime(string planArrivalTime, ArrayList arListMain)
        {
            string resTime = "";
            UtilityHelp.Instance.getFirstCenterPlanDepTime(Convert.ToDateTime(planArrivalTime), arListMain, out resTime);
            return resTime;
        }

        private string getNextSiteArrivalTime(string curSite, string planArrivalSiteConduct, string nextSite)
        {
            string arrivalNextSiteTime = "";
            try
            {
                bool isMainLine = false;
                if((nextSite.Contains("转运")&& curSite.Contains("转运"))|| (nextSite.Contains("转运") && curSite.Contains("分拨"))
                    || (nextSite.Contains("分拨") && curSite.Contains("分拨")) || (nextSite.Contains("分拨") && curSite.Contains("转运")))
                {
                    isMainLine = true;
                }
                if(isMainLine)
                {
                    if(LoadBasicHelper.Instance.m_ht_main_effi.ContainsKey(curSite))
                    {
                        Hashtable htMain = LoadBasicHelper.Instance.m_ht_main_effi[curSite] as Hashtable;
                        if(htMain.ContainsKey(nextSite))
                        {
                            ArrayList arListMain = htMain[nextSite] as ArrayList;
                            arrivalNextSiteTime=getMainLineArrivlTime(planArrivalSiteConduct, arListMain);
                        }


                    }
                }
                else
                {
                    if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(curSite))
                    {
                        Hashtable htSJ = LoadBasicHelper.Instance.m_ht_sh_effi[curSite] as Hashtable;
                        if (htSJ.ContainsKey(nextSite))
                        {
                            ArrayList arListSJ = htSJ[nextSite] as ArrayList;
                            UtilityHelp.Instance.getFirstPlanDepTime(Convert.ToDateTime(planArrivalSiteConduct), arListSJ, out arrivalNextSiteTime);
                        }
                    }

                }
            }
            catch(Exception ex)
            {

            }
            return arrivalNextSiteTime;
        }

        public bool isReallyLateIfUsingRightPlan(ArrayList arListAllSite, string centerName,string nextStopName,string planArrivalNextSiteConduct,string terminalDepTime,DateTime dtplanDep,DateTime dtPlanArrival)
        {
            bool res = true;
            try
            {
                if (arListAllSite.Contains(nextStopName))
                {
                    string nextSite = UtilityHelp.Instance.getNextSite(nextStopName, arListAllSite);
                    string nextSiteLatetArrial = "";
                    string lateButShouldDepTime = "";
                    ArrayList arListDisp = new ArrayList();
                    string lastArrivalDispatch = "";
                    if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(nextStopName))
                    {
                        Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[nextStopName] as Hashtable;
                        if(ht.ContainsKey(nextSite))
                        {
                            arListDisp = ht[nextSite] as ArrayList;
                            lastArrivalDispatch = UtilityHelp.Instance.getLastDispatchSiteArrival(arListDisp, planArrivalNextSiteConduct);
                        }
                    }
                    //先判断两个时间是否相同，相同则直接返回无延误
                    if (planArrivalNextSiteConduct != "" && terminalDepTime != "")
                    {
                        if (Convert.ToDateTime(planArrivalNextSiteConduct).ToShortDateString() == Convert.ToDateTime(terminalDepTime).ToShortDateString())
                        {
                            res = false;
                            string terminalDepHourTime = terminalDepTime.Substring(terminalDepTime.IndexOf(' ') + 1).Trim();
                            if(lastArrivalDispatch!="")
                            {
                                string lastDisHourTime= lastArrivalDispatch.Substring(lastArrivalDispatch.IndexOf(' ') + 1).Trim();
                                if(Convert.ToDateTime(lastDisHourTime)< Convert.ToDateTime(terminalDepHourTime))
                                {
                                    res = true;
                                }
                            }


                          
                            if(!res)
                            {
                                return res;
                            }
                        }
                    }

                    string lastDepTime = "";
                    if (!UtilityHelp.Instance.canGetLastCarDep(planArrivalNextSiteConduct.ToString(), nextStopName, nextSite, out nextSiteLatetArrial,out lastDepTime))
                    {
                        res = false;
                        if (nextSiteLatetArrial != "")
                        {
                            lateButShouldDepTime = UtilityHelp.Instance.shouldDepToReachNextSite(nextSiteLatetArrial, centerName, nextStopName);
                        }
                        if (lateButShouldDepTime != "" && utility.Utility.isTimeRight(dtplanDep))
                        {
                            if (Convert.ToDateTime(lateButShouldDepTime) < Convert.ToDateTime(planArrivalNextSiteConduct.ToString()))
                            {
                                lateButShouldDepTime = Convert.ToDateTime(dtPlanArrival.ToShortDateString()).AddDays(1).ToShortDateString() + " " + lateButShouldDepTime;
                            }
                            if (Convert.ToDateTime(lateButShouldDepTime) < dtplanDep)
                            {
                                res = true;
                            }
                        }
                    }


                }
            }
            catch(Exception ex)
            {

            }
            return res;
        }




        /// <summary>
        /// 转运中心发集散晚点延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isTerminalCenterDelay(ResultBean resultBean,  ArrayList arListAllSite, Hashtable htSiteTime, string dispatchSite, string dispatchSiteArrivalTime, Hashtable htAllTaskTime,string assignTime)
        {
            bool res = false;
            try
            {
                string jsSite = "";
                string lastCenter = "";
                if(!arListAllSite.Contains(dispatchSite))
                {
                    return res;
                }
                int indexDispatchSite = arListAllSite.IndexOf(dispatchSite);
                int jsSiteIndex = indexDispatchSite - 1;
                if(dispatchSite== arListAllSite[0].ToString())
                {
                    return res;
                }
                
                //jsSite = arListAllSite[jsSiteIndex].ToString();                
                string jsDepTime = "";
                string jsArrivalTime = "";
                //string assignTime = "";
                string lastCenterDepTime = "";
                string lastCenterPlanArriveTime = "";                
                string lastCenterActArriveTime = "";
                string lastCenterPlanDepTime = "";
                bool isContainJS = false;
                string jsActDepTime = "";
                string jsActArrialTime = "";
                string planArrivaJSUsingActDepTime = "";
                string planDispatchTime = "";

                int jsIndex = 0;
                int lastCenterIndex = 0;
                
                foreach (string strSiteName in arListAllSite)
                {
                    if(strSiteName.ToString().Contains("转运中心")|| strSiteName.ToString().Contains("分拨"))
                    {
                        lastCenter = strSiteName;
                        lastCenterIndex = arListAllSite.LastIndexOf(lastCenter);
                    }
                    if(strSiteName.ToString().Contains("集散"))
                    {
                        jsSite = strSiteName;
                        isContainJS = true;
                        jsIndex = arListAllSite.LastIndexOf(jsSite);
                        if(jsIndex- lastCenterIndex==1 && lastCenterIndex>0)
                        {
                            break;
                        }
                    }
                }

                if(jsSite== lastCenter)
                {
                    jsSite = dispatchSite;
                }
                if(!jsSite.Contains("集散"))
                {
                    return false;
                }
                if(jsIndex< lastCenterIndex)
                {
                    return false;
                }
                
                if (htAllTaskTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgBean = htAllTaskTime[lastCenter] as DbgBean;
                    if (utility.Utility.isTimeRight(dbgBean.lastPlannedArrival))
                    {
                        lastCenterPlanArriveTime = dbgBean.lastPlannedArrival.ToString();
                    }
                    if (utility.Utility.isTimeRight(dbgBean.lastActArrival))
                    {
                        lastCenterActArriveTime = dbgBean.lastActArrival.ToString();
                    }
                }


                if (htSiteTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgBean = htSiteTime[lastCenter] as DbgBean;
                    if (utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        //lastCenterDepTime = dbgBean.actualDepartureTime.ToString();
                        lastCenterDepTime = dbgBean.actualDepartureTime.ToString();
                    }
                }

                if(lastCenterDepTime!=""&& lastCenterPlanArriveTime!="")
                {
                    if(Convert.ToDateTime(lastCenterDepTime)< Convert.ToDateTime(lastCenterPlanArriveTime))
                    {
                        return false;
                    }
                }

                if(htSiteTime.ContainsKey(jsSite))
                {
                    DbgBean dbgB = htSiteTime[jsSite] as DbgBean;
                    if(utility.Utility.isTimeRight(dbgB.actualDepartureTime))
                    {
                        jsActDepTime = dbgB.actualDepartureTime.ToString();
                    }
                    if(utility.Utility.isTimeRight(dbgB.actualArrivalTime))
                    {
                        jsActArrialTime = dbgB.actualArrivalTime.ToString();
                    }
                }

                string concuteDateTime = lastCenterPlanArriveTime;
                if(lastCenterPlanArriveTime!=""&& lastCenterActArriveTime!="")
                {
                    /*if(Convert.ToDateTime(lastCenterActArriveTime)> Convert.ToDateTime(lastCenterPlanArriveTime))
                    {
                        concuteDateTime = lastCenterActArriveTime;
                    }*/
                }

                double addTime = 1;
                if (StoParams.Instance.isUseOperationTime)
                {
                    int rowIndex = arListAllSite.IndexOf(lastCenter);
                    if (rowIndex > 1)
                    {
                        string priorCenter = arListAllSite[rowIndex - 1].ToString();
                        addTime = UtilityHelp.Instance.getArrivaCenterAddHour(priorCenter, lastCenter, concuteDateTime);

                    }
                    else
                    {
                        addTime = 0;
                    }
                }

                //concuteDateTime = Convert.ToDateTime(concuteDateTime).AddHours(addTime).ToString();





                string planDepTimeToJS = "";
                string planArrivalJSTime = "";
                ArrayList arListJS2Dispatch = new ArrayList();
                bool isContainRouter = false;
                if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lastCenter))
                {
                    Hashtable htsiteMap = LoadBasicHelper.Instance.m_ht_sh_effi[lastCenter] as Hashtable;
                    if (htsiteMap.ContainsKey(jsSite))
                    {
                        ArrayList arListEffi = htsiteMap[jsSite] as ArrayList;

                        
                        if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(jsSite))
                        {
                            Hashtable htJSToSite = LoadBasicHelper.Instance.m_ht_sh_effi[jsSite] as Hashtable;
                            if(htJSToSite.ContainsKey(dispatchSite))
                            {
                                arListJS2Dispatch = htJSToSite[dispatchSite] as ArrayList;
                            }
                        }
                        /*if(arListJS2Dispatch.Count==0)
                        {
                            arListJS2Dispatch = LoadBasicHelper.Instance.getDispatchSite(dispatchSite);
                        }*/
                        string siteLatestArrivalTime = "11:00";
                        if(arListJS2Dispatch.Count>0)
                        {
                            siteLatestArrivalTime = UtilityHelp.Instance.getLastDispatchSiteArrival(arListJS2Dispatch, concuteDateTime);
                        }
                       
                        if(arListEffi.Count>0)
                        {
                            isContainRouter = true;
                        }
                        if (concuteDateTime != "")
                        {
                            planDepTimeToJS = UtilityHelp.Instance.getLastPlanDepTime(Convert.ToDateTime(concuteDateTime), arListEffi, siteLatestArrivalTime,out planArrivalJSTime, out planDispatchTime);
                        }
                        if(lastCenterDepTime!=""&&Convert.ToDateTime(lastCenterDepTime)< Convert.ToDateTime(concuteDateTime))
                        {
                            UtilityHelp.Instance.getLastPlanDepTimeUsingScanTime(Convert.ToDateTime(lastCenterDepTime), arListEffi, out planArrivaJSUsingActDepTime, out planDispatchTime);
                        }
                        else
                        {
                            planArrivaJSUsingActDepTime = planArrivalJSTime;
                        }

                        if (planDepTimeToJS == "")
                        {
                            foreach (SHTimeBean shBean in arListEffi)
                            {
                                if(UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(siteLatestArrivalTime, shBean.dtEffi))
                                {
                                    continue;
                                }
                                if (planDepTimeToJS == "")
                                {
                                    if (shBean.plannedDepartureTime != "")
                                    {
                                        planDepTimeToJS = shBean.plannedDepartureTime.ToString();
                                    }
                                    continue;

                                }
                                else
                                {
                                    if (shBean.plannedDepartureTime != "")
                                    {
                                        if (Convert.ToDateTime(shBean.plannedDepartureTime) > Convert.ToDateTime(planDepTimeToJS))
                                        {
                                            planDepTimeToJS = shBean.plannedDepartureTime;
                                        }
                                    }
                                }
                            }

                        }


                    }
                    else
                    {
                        if(Convert.ToDateTime(concuteDateTime).Hour<12)
                        {
                            planDepTimeToJS = concuteDateTime.Substring(0, concuteDateTime.IndexOf(' ') + 1) + "12:00";
                        }
                  
                    }

                    if (lastCenterDepTime != "" && planDepTimeToJS != "")
                    {
                        DateTime dtLastCenterDepTime = Convert.ToDateTime(lastCenterDepTime);
                        DateTime dtPlanDepTimeToJS = Convert.ToDateTime(planDepTimeToJS);

                        string planArrivalDispatchSiteUsingEraly = "";
                        bool isEarlyUsingEarlyRoute = UtilityHelp.Instance.isDateEarlyUsingEarlyRoute(dispatchSiteArrivalTime, lastCenterPlanArriveTime, lastCenter, jsSite, dispatchSite, jsActDepTime, assignTime,out planArrivalDispatchSiteUsingEraly);
                        //if ((Convert.ToDateTime(lastCenterDepTime) > Convert.ToDateTime(planDepTimeToJS))&& isEarlyUsingEarlyRoute)
                        if(isEarlyUsingEarlyRoute&& dtLastCenterDepTime > dtPlanDepTimeToJS)
                        {
                            res = true;
                            resultBean.dutySite = lastCenter;
                            resultBean.errorMsg = "末端转运晚发" + jsSite;
                            resultBean.errorType = "末端"+"中转延误";

                            if (resultBean.delayDays == "")
                            {
                                resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(planArrivalDispatchSiteUsingEraly), Convert.ToDateTime(dispatchSiteArrivalTime)).ToString();
                            }
                        }
                        else
                        {
                            //先判断用最近的时间路由发的话，是否到网点日期早于实际路由里的日期，单号 JT5092218442639 泉州晚发

                            //判断集散是否晚到，导致延误,根据上一站转运发集散的时间，推断集散最晚发到网点的时间，判断是否与网点的到件日期一致
                            //DateTime dtShouldArrivalJS=getShouldArrivalJisanTime(planDepTimeToJS, arListJS2Dispatch)
                            //if(planArrivalJSTime!="")
                            if (planArrivaJSUsingActDepTime!="")
                            {
                                string latestTime = "";
                                bool isSameDay = false;
                                //DateTime dtPlanArrivalJS = Convert.ToDateTime(planArrivalJSTime).Date;
                                DateTime dtPlanArrivalJS = Convert.ToDateTime(planArrivaJSUsingActDepTime).Date;
                                DateTime dtSiteArrial= Convert.ToDateTime(dispatchSiteArrivalTime).Date;

                                bool isLateForAll = false;

                                string strLatestTimeTm = "";
                                UtilityHelp.Instance.getLastJisanPlanDepTime(Convert.ToDateTime(planArrivaJSUsingActDepTime), arListJS2Dispatch, out isLateForAll, out strLatestTimeTm, out planDispatchTime);

                                if((dtPlanArrivalJS== dtSiteArrial&& Convert.ToDateTime(dispatchSiteArrivalTime).Hour<=13) ||dtPlanArrivalJS> dtSiteArrial)
                                {
                                    isSameDay = true;
                                }
                                if(jsActArrialTime!="")
                                {
                                    if (Convert.ToDateTime(dispatchSiteArrivalTime).Date == Convert.ToDateTime(jsActArrialTime).Date)
                                    {
                                        isSameDay = true;
                                    }
                                    
                                    if (planDispatchTime!=""&&Convert.ToDateTime(dispatchSiteArrivalTime).Date == Convert.ToDateTime(planDispatchTime).Date)
                                    {
                                        isSameDay = true;
                                    }

                                }
                                string lastJSDepTime = "";
                                //if (UtilityHelp.Instance.canGetLastCarDep(planArrivalJSTime, jsSite,dispatchSite,out latestTime)&&!isSameDay)
                                if (UtilityHelp.Instance.canGetLastCarDep(planArrivaJSUsingActDepTime, jsSite, dispatchSite, out latestTime,out lastJSDepTime) && !isSameDay)
                                {
                                    if(latestTime=="")
                                    {
                                        latestTime = "12:00";
                                    }
                                    //string shouldDep = planArrivalJSTime.Substring(0, planArrivalJSTime.IndexOf(' '))+" "+ latestTime;
                                    string shouldDep = planArrivaJSUsingActDepTime.Substring(0, planArrivaJSUsingActDepTime.IndexOf(' ')) + " " + latestTime;
                                    if(lastJSDepTime!=""&& shouldDep!="")
                                    {
                                        if(Convert.ToDateTime(shouldDep)<Convert.ToDateTime(lastJSDepTime)&& Convert.ToDateTime(shouldDep).Date == Convert.ToDateTime(lastJSDepTime).Date)
                                        {
                                            shouldDep = lastJSDepTime;
                                        }
                                    }

                                    if (Convert.ToDateTime(jsActDepTime)> Convert.ToDateTime(shouldDep))
                                    {
                                        res = true;
                                        resultBean.dutySite = jsSite;
                                        resultBean.errorMsg = "集散晚到件延误 " + jsSite;
                                        resultBean.errorType = "集散晚到件延误";

                                        if (resultBean.delayDays == "")
                                        {
                                            resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(shouldDep), Convert.ToDateTime(jsActDepTime)).ToString();
                                        }

                                    }
                                   
                                }
                            }

                        }
                    }

                    else if (lastCenterDepTime == "")
                    {
                        //针对转运未做发件的处理
                        if (planArrivalJSTime != "" && jsActArrialTime != "")
                        {
                            TimeSpan ts = Convert.ToDateTime(jsActArrialTime) - Convert.ToDateTime(planArrivalJSTime);
                            if (ts.TotalHours > 4)
                            {
                                res = true;
                            }
                        }
                        else
                        {
                            res = true;
                        }
                        if (res)
                        {
                            resultBean.dutySite = lastCenter;
                            resultBean.errorMsg = "末端转运晚发" + jsSite;
                            resultBean.errorType = "末端"+"中转延误";
                            resultBean.shouldLeaveTime = planArrivalJSTime;
                            return res;
                        }


                    }
                }

                
                    //针对集散时效表里不存在的集散名称处理
                if (planDepTimeToJS==""&&!isContainRouter)
                {
                    if (jsActArrialTime != "" && jsActDepTime != "" )
                    {                        
                        DateTime dtActArrival = Convert.ToDateTime(jsActArrialTime);
                        DateTime dtActDep = Convert.ToDateTime(jsActDepTime);
                        if(assignTime != "")
                        {
                            //先判断集散到件时间和派件网点签收时间是否同一天，同一天则直接无延误
                            DateTime dtAssign = Convert.ToDateTime(assignTime);
                            if (dtActArrival.Date == dtAssign.Date)
                            {
                                res = false;
                                return false;
                            }
                        }
                        else
                        {
                            //判断集散到件时间和到网点时间是否同一天，且发件时间小于网点最迟发件时间

                            if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(jsSite))
                            {
                                Hashtable htJSToSite = LoadBasicHelper.Instance.m_ht_sh_effi[jsSite] as Hashtable;
                                if (htJSToSite.ContainsKey(dispatchSite))
                                {
                                    arListJS2Dispatch = htJSToSite[dispatchSite] as ArrayList;
                                }
                            }
                            bool islateForAllPlan = false;
                            string latestTime = "";
                            string planDispatchTimeNew = "";
                            string planJisanDep=UtilityHelp.Instance.getLastJisanPlanDepTime(dtActArrival, arListJS2Dispatch, out islateForAllPlan, out latestTime, out planDispatchTimeNew);
                            if(planJisanDep!="")
                            {
                                DateTime dtPlanDepJisan = Convert.ToDateTime(planJisanDep);
                                if(dtPlanDepJisan<dtActDep)
                                {
                                    res = true;
                                    resultBean.dutySite = jsSite;
                                    resultBean.errorMsg = "集散未及时转出 " + jsSite;
                                    resultBean.errorType = "集散未及时转出";
                                    if (resultBean.delayDays == "")
                                    {
                                        resultBean.delayDays = Utility.getDelayDays(dtPlanDepJisan, dtActDep).ToString();
                                    }
                                }
                            }


                        }

                        
                        /*if (dtActArrival.Date == dtActDep.Date)
                        {
                            if (dtActDep.Hour <= 13)
                            {
                                return false;
                            }
                            if (dtActArrival.Hour <= 13 && dtActDep.Hour > 13)
                            {
                                res = true;
                                resultBean.dutySite = jsSite;
                                resultBean.errorMsg = "集散未及时转出 " + jsSite;
                                resultBean.errorType = "集散未及时转出";
                            }
                        }
                        else
                        {
                            TimeSpan ts = dtActDep - dtActArrival;
                            if (ts.TotalHours > 12)
                            {
                                res = true;
                                resultBean.dutySite = jsSite;
                                resultBean.errorMsg = "集散未及时转出 " + jsSite;
                                resultBean.errorType = "集散未及时转出";
                            }
                        }*/
                    }
                }

                if (res)
                {
                    /*if (htAllTaskTime.ContainsKey(lastCenter))
                    {
                        bool moreThan24Hours = false;
                        if (lastCenterDepTime != "" && planDepTimeToJS != "")
                        {
                            TimeSpan ts = Convert.ToDateTime(lastCenterDepTime) - Convert.ToDateTime(planDepTimeToJS);
                            if (ts.TotalHours > 24)
                            {
                                moreThan24Hours = true;
                            }
                        }

                        DbgBean dbgBean = htAllTaskTime[lastCenter] as DbgBean;
                        if (utility.Utility.isTimeRight(dbgBean.plannedArrivalTime) && utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                        {
                            if (dbgBean.actualArrivalTime > dbgBean.plannedArrivalTime && !moreThan24Hours)
                            {
                                res = false;
                            }
                        }

                    }*/


                }



            }
            catch (Exception ex)
            {

            }
            return res;
        }


        private bool isTerminalProblemDelay(ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime, string dispatchSite, string dispatchSiteArrivalTime, Hashtable htAllTaskTime,ArrayList arlistRoadMap)
        {
            bool res = false;
            try
            {
                RoadBean priorRoadBean = new RoadBean();
                int roadIndex = 0;
                foreach (RoadBean roadBean in arlistRoadMap)
                {
                    if(roadBean.waybillTrackingContent.Contains("有发未到件"))
                    {
                        RoadBean nextRoadBean = (RoadBean)arlistRoadMap[roadIndex + 1];
                        if(nextRoadBean.scanNetworkName== roadBean.scanNetworkName)
                        {
                            TimeSpan ts = Convert.ToDateTime(nextRoadBean.scanTime) - Convert.ToDateTime(roadBean.scanTime);
                            if(ts.TotalHours>24)
                            {
                                res = true;
                                resultBean.dutySite = priorRoadBean.scanNetworkName;
                                resultBean.errorMsg = "末端延误";
                                return res;
                            }
                        }

                    }
                    priorRoadBean = roadBean;
                    roadIndex++;
                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }


        /// <summary>
        /// 集散晚发/转运中心发晚点延误
        /// </summary>
        /// <param name="resultBean"></param>
        /// <param name="arListAllSite"></param>
        /// <param name="htSiteTime"></param>
        /// <returns></returns>
        private bool isWaybillSJDelay(ResultBean resultBean, ArrayList arListAllSite, Hashtable htSiteTime,string dispatchSite,string dispatchSiteArrivalTime,Hashtable htAllTaskTime)
        {
            bool res = false;
            try
            {
                if(resultBean.errorMsg.Contains("退回"))
                {
                    return false;
                }
                string jsSite = "";
                string lastCenter = "";


                int indexDispatchSite = arListAllSite.IndexOf(dispatchSite);
                int jsSiteIndex = indexDispatchSite - 1;
                jsSite = arListAllSite[jsSiteIndex].ToString();
                lastCenter= arListAllSite[jsSiteIndex-1].ToString();
                string jsDepTime = "";
                string jsArrivalTime = "";
                string assignTime = "";
                string dutyDesc = "集散点";
                string lastCenterPlanArrivalTime = "";

                Hashtable htCarLateMap = new Hashtable();

                string lastCenterDepTime = "";
                if(jsSite.Contains("转运中心")|| jsSite.Contains("分拨"))
                {
                    dutyDesc = "末端";
                    lastCenter = jsSite;
                }

                if (htSiteTime.ContainsKey(dispatchSite))
                {
                    DbgBean dbgBean = htSiteTime[dispatchSite] as DbgBean;
                    if (utility.Utility.isTimeRight(dbgBean.assignTime))
                    {
                        assignTime = dbgBean.assignTime.ToString();
                    }
                }

                if (htSiteTime.ContainsKey(jsSite))
                {
                    DbgBean dbgBean = htSiteTime[jsSite] as DbgBean;

                    DateTime dtProblem = dbgBean.problemNotArrivalTime;
                    if(utility.Utility.isTimeRight(dtProblem))
                    {
                        if(utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                        {
                            if(UtilityHelp.Instance.isTimeInDifferentDays(dtProblem, dbgBean.actualArrivalTime))
                            {
                                resultBean.dutySite = jsSite;
                                resultBean.errorMsg = dutyDesc+"晚发" + dispatchSite;
                                resultBean.errorType = "问题件";
                                if(utility.Utility.isTimeRight(dbgBean.plannedDepartureTime))
                                {
                                    resultBean.shouldLeaveTime = dbgBean.plannedDepartureTime.ToString();
                                }
                                else if(utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                                {
                                    resultBean.shouldLeaveTime = dbgBean.actualDepartureTime.ToString();
                                }
                                if (resultBean.delayDays == "")
                                {
                                    resultBean.delayDays = Utility.getDelayDays(dbgBean.plannedDepartureTime, dbgBean.actualArrivalTime).ToString();
                                }
                                res = true;
  
                            }
                        }
                    }

                    /*if (UtilityHelp.Instance.isTimeInDifferentDays(dbgBean.arListDepTimes))
                    {
                        resultBean.dutySite = jsSite;
                        resultBean.errorMsg = dutyDesc + "晚发" + dispatchSite;
                        resultBean.errorType = dutyDesc + "未及时转出";
                        res = true;

                    }*/
                    if(utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        jsDepTime = dbgBean.actualDepartureTime.ToString();
                    }
                    if (utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                    {
                        jsArrivalTime = dbgBean.actualArrivalTime.ToString();
                    }
                }

               
                if(htSiteTime.ContainsKey(lastCenter))
                {
                    DbgBean dbgBean = htSiteTime[lastCenter] as DbgBean;
                    if(utility.Utility.isTimeRight(dbgBean.actualDepartureTime))
                    {
                        lastCenterDepTime = dbgBean.actualDepartureTime.ToString();
                    }                   
                }

                string planArrivalJS = "";
                if (htAllTaskTime.ContainsKey(jsSite))
                {
                    DbgBean dbgJs = htAllTaskTime[jsSite] as DbgBean;
                    //2023-3-20 lastPlannedArrivalTime修改为 plannedArrivalTime
                    if (utility.Utility.isTimeRight(dbgJs.plannedArrivalTime))
                    {
                        planArrivalJS = dbgJs.plannedArrivalTime.ToString();
                        lastCenterPlanArrivalTime = planArrivalJS;
                    }

                    if (utility.Utility.isTimeRight(dbgJs.lastActArrival))
                    {
                        jsArrivalTime = dbgJs.lastActArrival.ToString();
                    }
                    if (utility.Utility.isTimeRight(dbgJs.actualArrivalTime))
                    {
                        if(dbgJs.actualArrivalTime<Convert.ToDateTime(jsArrivalTime))
                        {
                            jsArrivalTime = dbgJs.actualArrivalTime.ToString();
                        }
                    }

                    if (jsArrivalTime!=""&&Convert.ToDateTime(jsArrivalTime)> Convert.ToDateTime(planArrivalJS)&& !jsSite.Contains("转运中心")&& !jsSite.Contains("分拨"))
                    {
                        planArrivalJS = jsArrivalTime;
                        lastCenterPlanArrivalTime = planArrivalJS;
                    }

                }
                else
                {
                    if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(lastCenter) && lastCenterDepTime != "")
                    {
                        Hashtable htCenterSite = LoadBasicHelper.Instance.m_ht_sh_effi[lastCenter] as Hashtable;
                        if (htCenterSite.ContainsKey(jsSite))
                        {
                            ArrayList arListEffi = htCenterSite[jsSite] as ArrayList;
                            planArrivalJS = UtilityHelp.Instance.getMostRecentArrivaTime(Convert.ToDateTime(lastCenterDepTime), arListEffi);
                        }
                    }


                    }
                /*}*/


                string  jsConcute = planArrivalJS;

                bool usePlanArrival = true;

                if (planArrivalJS=="")
                {
                    jsConcute = jsArrivalTime;
                    htCarLateMap[jsSite] = jsSite;
                    usePlanArrival = false;
                }
                
                /*if(planArrivalJS!=""&& jsArrivalTime!="")
                {
                    if(Convert.ToDateTime(jsArrivalTime)< Convert.ToDateTime(planArrivalJS)&&!jsSite.Contains("转运中心") && !jsSite.Contains("分拨"))
                    {
                        jsConcute = jsArrivalTime;
                        usePlanArrival = false;
                    }
                }*/
                //jsConcute = Convert.ToDateTime(jsConcute).AddHours(1).ToString();

                string planDepTimeToNetSite = "";
                string lastSitePlanArrival = "";
                string planDispatchTime = "";
                if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(jsSite))
                {
                    Hashtable htsiteMap = LoadBasicHelper.Instance.m_ht_sh_effi[jsSite] as Hashtable;
                    if(htsiteMap.ContainsKey(dispatchSite))
                    {
                        ArrayList arListEffi = htsiteMap[dispatchSite] as ArrayList;
                        if(jsConcute != "")
                        {
                            bool isLateForAllPlan = false;
                            string latestArrivalTime = "";
                            if(usePlanArrival)
                            {
                                planDepTimeToNetSite = UtilityHelp.Instance.getLastJisanPlanDepTime(Convert.ToDateTime(jsConcute), arListEffi, out isLateForAllPlan, out latestArrivalTime,out planDispatchTime);
                            }
                            else
                            {
                                planDepTimeToNetSite = UtilityHelp.Instance.getLastPlanDepTimeUsingScanTime(Convert.ToDateTime(jsConcute), arListEffi, out lastSitePlanArrival,out planDispatchTime);
                            }
                           
                        }

                        if(planDepTimeToNetSite=="")
                        {
                            foreach (SHTimeBean shBean in arListEffi)
                            {
                                if (UtilityHelp.Instance.isBeanEffieLateThanCurSiteTime(jsArrivalTime, shBean.dtEffi))
                                {
                                    continue;
                                }

                                if (planDepTimeToNetSite == "")
                                {
                                    if (shBean.plannedDepartureTime != "")
                                    {
                                        planDepTimeToNetSite = shBean.plannedDepartureTime.ToString();
                                    }
                                    continue;

                                }
                                else
                                {
                                    if (shBean.plannedDepartureTime != "")
                                    {
                                        if (Convert.ToDateTime(shBean.plannedDepartureTime) > Convert.ToDateTime(planDepTimeToNetSite))
                                        {
                                            planDepTimeToNetSite = shBean.plannedDepartureTime;
                                        }
                                    }
                                }
                            }

                            if(!planDepTimeToNetSite.Contains("-"))
                            {
                                if(jsArrivalTime!="")
                                {
                                    DateTime dtArriveJS = Convert.ToDateTime(jsArrivalTime);
                                    int add = 0;
                                    if(dtArriveJS.Hour>12)
                                    {
                                        add = 1;
                                    }
                                    planDepTimeToNetSite = Convert.ToDateTime(dtArriveJS.AddDays(add)).ToShortDateString() + " " + planDepTimeToNetSite;
                                }
                            }
                        }
                        

                    }
                    else
                    {
                        if(jsArrivalTime!=""&& planArrivalJS!=""&& jsDepTime!="")
                        {
                            DateTime dtPlanArrivalJS = Convert.ToDateTime(planArrivalJS);
                            DateTime dtJSArrival = Convert.ToDateTime(jsArrivalTime);
                            DateTime dtJSDepTime = Convert.ToDateTime(jsDepTime);
                            if(dispatchSiteArrivalTime=="")
                            {
                                dispatchSiteArrivalTime = assignTime;
                            }
                            DateTime dtDispatchArrival = Convert.ToDateTime(dispatchSiteArrivalTime);
                            if (dtPlanArrivalJS.Hour<12&& (dtJSArrival.ToShortDateString()!= dtPlanArrivalJS.ToShortDateString()|| dtJSDepTime.Hour>12))
                            {
                                TimeSpan ts = dtJSArrival - dtPlanArrivalJS;
                                if(ts.TotalHours>1)
                                {
                                    res = true;
                                    resultBean.dutySite = jsSite;
                                    resultBean.errorMsg = dutyDesc + "晚发" + dispatchSite;
                                    resultBean.errorType = dutyDesc + "中转延误";
                                    resultBean.shouldLeaveTime = jsDepTime;
                                    if(resultBean.delayDays=="")
                                    {
                                        resultBean.delayDays = Utility.getDelayDays(dtPlanArrivalJS, dtJSArrival).ToString();
                                    }
                                    
                                }
                            }
                        }
                    }
               
                    if(jsDepTime!=""&& planDepTimeToNetSite!="")
                    {
                        if (Convert.ToDateTime(jsDepTime) > Convert.ToDateTime(planDepTimeToNetSite))
                        {

                            res = true;
                            resultBean.dutySite = jsSite;
                            resultBean.errorMsg = dutyDesc + "晚发" + dispatchSite;
                            resultBean.errorType = dutyDesc + "中转延误";
                            resultBean.shouldLeaveTime = planDepTimeToNetSite;
                            if (resultBean.delayDays == "")
                            {
                                resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(planDepTimeToNetSite), Convert.ToDateTime(jsDepTime)).ToString();
                            }
                            else
                            {
                                int delayDays = Convert.ToInt32(resultBean.delayDays);
                                if(delayDays>30)
                                {
                                    resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(planDepTimeToNetSite), Convert.ToDateTime(jsDepTime)).ToString();
                                }
                            }

                               
                            if (dispatchSiteArrivalTime!="")
                            {
                                if(Convert.ToDateTime(dispatchSiteArrivalTime).Date==Convert.ToDateTime(planDepTimeToNetSite).Date)
                                {
                                    res = false;
                                }
                                if(planDispatchTime!=""&& Convert.ToDateTime(dispatchSiteArrivalTime).Date <= Convert.ToDateTime(planDispatchTime).Date)
                                {
                                    res = false;
                                }
                           
                            }
                        }
                    }
                }
                if(!res&&(jsSite.Contains("转运中心")|| jsSite.Contains("分拨")))
                {
                    string planArrivaJSUsingActDepTime = lastCenterPlanArrivalTime;
                    if(jsDepTime=="")
                    {
                        ArrayList arListEffi = new ArrayList();
                        if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(jsSite))
                        {
                            Hashtable htCenterSite = LoadBasicHelper.Instance.m_ht_sh_effi[jsSite] as Hashtable;
                            if (htCenterSite.ContainsKey(dispatchSite))
                            {
                                arListEffi = htCenterSite[dispatchSite] as ArrayList;                               
                            }
                        }
                        if(arListEffi.Count>0)
                        {
                            string lastPlanArrival = "";
                            string lastPlanDispatch = "";
                            UtilityHelp.Instance.getLastPlanDepTime(Convert.ToDateTime(lastCenterPlanArrivalTime), arListEffi, dispatchSiteArrivalTime, out lastPlanArrival, out lastPlanDispatch);
                            if(lastPlanDispatch!="")
                            {
                                if(Convert.ToDateTime(lastPlanDispatch).Date<Convert.ToDateTime(dispatchSiteArrivalTime).Date)
                                {
                                    if (resultBean.delayDays == "")
                                    {
                                        resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(lastPlanDispatch),  Convert.ToDateTime(dispatchSiteArrivalTime)).ToString();
                                    }
                                    res = true;
                                }
                            }

                        }
                        else
                        {
                            if (Convert.ToDateTime(lastCenterPlanArrivalTime).Date < Convert.ToDateTime(dispatchSiteArrivalTime).Date)
                            {
                                if (resultBean.delayDays == "")
                                {
                                    resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(lastCenterPlanArrivalTime), Convert.ToDateTime(dispatchSiteArrivalTime)).ToString();
                                }
                                res = true;
                            }
                              
                        }
                        if(res)
                        {
                            if (resultBean.delayDays == "")
                            {
                                resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(planDepTimeToNetSite), Convert.ToDateTime(jsDepTime)).ToString();
                            }                                
                            resultBean.dutySite = jsSite;
                            resultBean.errorMsg = "末端未及时转出 " + dispatchSite;
                            resultBean.errorType = "末端中转延误";
                        }
                    }
                    /*if(jsArrivalTime!="")
                    {
                        if(htAllTaskTime.ContainsKey(jsSite))
                        {
                            DbgBean dbg = htAllTaskTime[jsSite] as DbgBean;
                            if(dbg.plannedArrivalTime==Convert.ToDateTime(lastCenterPlanArrivalTime))
                            {
                                string jsActArrivalTime = dbg.actualArrivalTime.ToString();
                                if(Convert.ToDateTime(jsActArrivalTime)>Convert.ToDateTime(planArrivaJSUsingActDepTime))
                                {
                                    planArrivaJSUsingActDepTime = jsActArrivalTime;
                                }
                                    
                            }
                        }
                    }*/
                    //判断转运是否晚到件导致延误
                    if (planArrivaJSUsingActDepTime != "")
                    {
                        string latestTime = "";
                        bool isSameDay = false;
                        //DateTime dtPlanArrivalJS = Convert.ToDateTime(planArrivalJSTime).Date;
                        DateTime dtPlanArrivalJS = Convert.ToDateTime(planArrivaJSUsingActDepTime).Date;
                        DateTime dtSiteArrial = Convert.ToDateTime(dispatchSiteArrivalTime).Date;
                        if ((dtPlanArrivalJS == dtSiteArrial && Convert.ToDateTime(dispatchSiteArrivalTime).Hour <= 13) || dtPlanArrivalJS > dtSiteArrial)
                        {
                            isSameDay = true;
                        }
                        string lastDepTime = "";
                        //if (UtilityHelp.Instance.canGetLastCarDep(planArrivalJSTime, jsSite,dispatchSite,out latestTime)&&!isSameDay)
                        if (UtilityHelp.Instance.canGetLastCarDep(planArrivaJSUsingActDepTime, jsSite, dispatchSite, out latestTime,out lastDepTime) && !isSameDay)
                        {
                            bool isFindSJRoad = true;
                            if (latestTime == "")
                            {
                                isFindSJRoad = false;
                                latestTime = "12:00";
                            }
                            //string shouldDep = planArrivalJSTime.Substring(0, planArrivalJSTime.IndexOf(' '))+" "+ latestTime;
                            string shouldArrival = planArrivaJSUsingActDepTime.Substring(0, planArrivaJSUsingActDepTime.IndexOf(' ')) + " " + latestTime;
                            //找不到运力关系映射表
                            if(Convert.ToDateTime(shouldArrival)< Convert.ToDateTime(planArrivaJSUsingActDepTime))
                            {
                               if(Convert.ToDateTime(jsArrivalTime).Date== Convert.ToDateTime(shouldArrival).Date)
                               {
                                    if(Convert.ToDateTime(jsArrivalTime).Hour>15)
                                    {
                                        res = false;
                                        return res;
                                    }
                               }
                               if(!isFindSJRoad)
                                {
                                    shouldArrival = planArrivaJSUsingActDepTime;
                                }
                            }
                            if (Convert.ToDateTime(jsArrivalTime) > Convert.ToDateTime(shouldArrival)&& dtPlanArrivalJS< dtSiteArrial)
                            {
                                res = true;
                                resultBean.dutySite = jsSite;
                                resultBean.errorMsg = "末端晚到件延误 " + jsSite;
                                resultBean.errorType = "末端晚到件延误";
                                if (resultBean.delayDays == "")
                                {
                                    resultBean.delayDays = Utility.getDelayDays(Convert.ToDateTime(shouldArrival), Convert.ToDateTime(jsArrivalTime)).ToString();
                                }
                                   

                                if (planDepTimeToNetSite!="")
                                {
                                    if(Convert.ToDateTime(planDepTimeToNetSite).Date== Convert.ToDateTime(jsArrivalTime).Date)
                                    {
                                        TimeSpan ts = Convert.ToDateTime(jsArrivalTime) - Convert.ToDateTime(shouldArrival);
                                        if(ts.TotalHours<1)
                                        {
                                            res = false;
                                        }
                                    }
                                }

                            }

                        }
                    }



                }

                if(res)
                {
                    /*if(htAllTaskTime.ContainsKey(jsSite))
                    {
                        bool moreThan24Hours = false;
                        if (jsDepTime != "" && planDepTimeToNetSite != "")
                        {
                            TimeSpan ts = Convert.ToDateTime(jsDepTime) - Convert.ToDateTime(planDepTimeToNetSite);
                            if(ts.TotalHours>24)
                            {
                                moreThan24Hours = true;
                            }
                        }
                           
                        DbgBean dbgBean = htAllTaskTime[jsSite] as DbgBean;
                        if(utility.Utility.isTimeRight(dbgBean.plannedArrivalTime)&& utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                        {
                            if(dbgBean.actualArrivalTime> dbgBean.plannedArrivalTime&& !moreThan24Hours)
                            {
                                res = false;
                            }
                        }

                    }*/
                    if(htCarLateMap.ContainsKey(jsSite))
                    {
                        resultBean.errorType = dutyDesc + "中转延误 "+"司机延误";
                    }
                }



            }
            catch(Exception ex)
            {

            }
            return res;
        }

   

        private void getLastOmitRoadDbgEachSite(ArrayList arListAllRoadMap, ArrayList arListAllSite, Hashtable htSiteTime, ArrayList arListAllGXTask, ArrayList arListAllCenters)
        {
            try
            {
                int curIndex = 0;
                string priorNext = "";
                bool isAssignAppear = false;
                for (int i= arListAllRoadMap.Count-1; i>arListAllRoadMap.Count/2;i--)
                {
                    RoadBean roadBean = (RoadBean)arListAllRoadMap[i];
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    if(nextName.Contains("集散")&& (siteName.Contains("转运中心")|| siteName.Contains("分拨")) && scanType.Contains("发件"))
                    {
                        string planArrivalJS = "";

                        if(!htSiteTime.ContainsKey(nextName))
                        {
                            DbgBean dbgBean = new bean.DbgBean();
                            if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(siteName))
                            {
                                Hashtable ht = LoadBasicHelper.Instance.m_ht_sh_effi[siteName] as Hashtable;
                                if(ht.ContainsKey(nextName))
                                {
                                    ArrayList arListEffi = ht[nextName] as ArrayList;
                                    UtilityHelp.Instance.getFirstPlanArrialTime(Convert.ToDateTime(scanTime), arListEffi, out planArrivalJS);
                                    if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(nextName))
                                    {
                                        string dispatch = arListAllSite[arListAllSite.IndexOf(siteName) + 1].ToString();
                                        if(!dispatch.Contains("网点"))
                                        {
                                            return;
                                        }
                                        if(LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(nextName))
                                        {
                                            Hashtable htDispatch = LoadBasicHelper.Instance.m_ht_sh_effi[nextName] as Hashtable;
                                            if (htDispatch.ContainsKey(dispatch))
                                            {
                                                ArrayList arListDisp = htDispatch[dispatch] as ArrayList;
                                                string planArrivalDis = "";
                                                string firsPlanDep=UtilityHelp.Instance.getFirstPlanDepTime(Convert.ToDateTime(planArrivalJS), arListDisp, out planArrivalDis);
                                                if(firsPlanDep!="")
                                                {
                                                    dbgBean.actualArrivalTime = Convert.ToDateTime(planArrivalJS);
                                                    dbgBean.actualDepartureTime = Convert.ToDateTime(firsPlanDep);
                                                    dbgBean.arListDepTimes.Add(firsPlanDep);
                                                    htSiteTime[nextName] = dbgBean;
                                                    if(!arListAllSite.Contains(nextName))
                                                    {
                                                        arListAllSite.Insert(arListAllSite.IndexOf(siteName) + 1, nextName);
                                                    }


                                                }

                                            }

                                        }
                                    }

                                    

                                }
                            }

                        }
                        return;
                    }

                }

            }
            catch (Exception ex)
            {

            }
        }


        private void handleLastCenterArrivalTime(ArrayList arListAllRoadMap, ArrayList arListAllSite, 
            ArrayList arListAllCenters, Hashtable htSiteTime,Hashtable htAllTaskTime,Hashtable htCenterFromList)
        {
            try
            {
                foreach(string strSite in arListAllSite)
                {
                    if(strSite.Contains("转运")|| strSite.Contains("分拨"))
                    {
                        if(!arListAllCenters.Contains(strSite))
                        {
                            foreach (RoadBean roadBean in arListAllRoadMap)
                            {
                                string siteName = roadBean.scanNetworkName;
                                if(siteName== strSite&& roadBean.scanTypeName.Contains("发件"))
                                {
                                    arListAllCenters.Add(strSite);
                                    if (!htAllTaskTime.ContainsKey(strSite))
                                    {
                                        htAllTaskTime[strSite] = new DbgBean();
                                    }
                                    break;
                                }
                            }


                               
                        }
                        
                    }
                }

                foreach(RoadBean roadBean in arListAllRoadMap)
                {
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    if (siteName.Contains("转运中心") || siteName.Contains("分拨"))
                    {
                        if(nextName.Contains("转运中心") || nextName.Contains("分拨"))
                        {
                            string planArrivalNext = roadBean.plannedArrivalTime;
                            if(htSiteTime.Contains(nextName)&& planArrivalNext!="")
                            {
                               
                                if(htCenterFromList.ContainsKey(siteName))
                                {
                                    ArrayList arListTaskNos = htCenterFromList[siteName] as ArrayList;
                                    if(arListTaskNos.Count==1)
                                    {
                                        DbgBean nextCenterDbg = htSiteTime[nextName] as DbgBean;
                                        //if (!utility.Utility.isTimeRight(nextCenterDbg.plannedArrivalTime))
                                        {
                                            nextCenterDbg.plannedArrivalTime = Convert.ToDateTime(planArrivalNext);
                                        }

                                        if (htAllTaskTime.ContainsKey(nextName))
                                        {
                                          
                                            DbgBean tmpDbg = htAllTaskTime[nextName] as DbgBean;
                                            //if (!utility.Utility.isTimeRight(tmpDbg.plannedArrivalTime))
                                            {
                                                tmpDbg.plannedArrivalTime = Convert.ToDateTime(planArrivalNext);
                                            }

                                        }
                                    }
                                }
                                
                                
                            }
                        }
                        
                    }
                }

            }
            catch(Exception ex)
            {

            }
        }

        private void getRoadDbgEachSite(ArrayList arListAllRoadMap, ArrayList arListAllSite,
            Hashtable htSiteTime,ArrayList arListAllGXTask,ArrayList arListAllCenters,Hashtable htAllSiteRightTime)
        {
            try
            {
                int curIndex = 0;
                string priorNext = "";
                bool isAssignAppear = false;
                string priorDepSite = "";
                bool isCenterAppear = false;
                foreach (RoadBean roadBean in arListAllRoadMap)
                {
                    string siteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string scanTime = roadBean.scanTime;
                    curIndex++;
                    if (scanTime=="")
                    {
                        continue;
                    }
                    if(siteName.Contains("转运中心")|| siteName.Contains("分拨"))
                    {
                        isCenterAppear = true;
                    }
                    if (roadBean.dkgx != "" && !arListAllGXTask.Contains(roadBean.dkgx))
                    {
                        arListAllGXTask.Add(roadBean.dkgx);
                       
                    }
                    siteName = UtilityHelp.Instance.getMapedCenter(siteName);
                    if (!htSiteTime.ContainsKey(siteName))
                    {
                        if(siteName!="")
                        {
                            htSiteTime[siteName] = new DbgBean();
                        }
                        else
                        {
                            if(curIndex> arListAllRoadMap.Count-2)
                            {
                                siteName = priorNext;
                                if(!htSiteTime.ContainsKey(siteName))
                                {
                                    htSiteTime[siteName]= new DbgBean();
                                }
                            }
                        }
                        
                    }

                    if(nextName.Contains("转运")|| nextName.Contains("分拨"))
                    {
                        if(!htSiteTime.ContainsKey(nextName))
                        {
                            htSiteTime[nextName] = new DbgBean();
                        }
                       
                    }
                    
                    DbgBean dbgBean = htSiteTime[siteName] as DbgBean;

                    if (scanType.Contains("问题件扫描") && roadBean.waybillTrackingContent.Contains("有发未到件"))
                    {
                        dbgBean.problemNotArrivalTime = Convert.ToDateTime(scanTime);
                    }
                    else
                    {
                        if (!htAllSiteRightTime.ContainsKey(siteName))
                        {
                            htAllSiteRightTime[siteName] = dbgBean;
                        }

                    }
                    if (roadBean.dkgx != "")
                    {
                        if(dbgBean.firstTaskNo=="")
                        {
                            dbgBean.firstTaskNo = roadBean.dkgx;
                        }
                        else if(dbgBean.firstTaskNo != roadBean.dkgx&& dbgBean.secondTaskNo=="")
                        {
                            dbgBean.secondTaskNo = roadBean.dkgx;
                        }

                        if(htSiteTime.ContainsKey(nextName))
                        {
                            DbgBean nextDbg = htSiteTime[nextName] as DbgBean;
                            if (nextDbg.firstTaskNo == "")
                            {
                                nextDbg.firstTaskNo = roadBean.dkgx;
                            }
                            else if (nextDbg.firstTaskNo != roadBean.dkgx)
                            {
                                nextDbg.secondTaskNo = roadBean.dkgx;
                            }
                        }
                    }

                    if (scanType.Contains("卸车") || scanType.Contains("到件") || scanType.Contains("建包扫描"))
                    {  
                        if(!utility.Utility.isTimeRight(dbgBean.actualArrivalTime))
                        {
                            dbgBean.actualArrivalTime = Convert.ToDateTime(scanTime);
                        } 
                        if(!arListAllCenters.Contains(siteName)&& ((siteName.Contains("转运")|| siteName.Contains("分拨"))))
                        {
                            arListAllCenters.Add(siteName);
                        } 
                        
                        if(!utility.Utility.isTimeRight(dbgBean.firstArrival))
                        {
                            dbgBean.firstArrival = Convert.ToDateTime(scanTime);
                        }
                        if (utility.Utility.isTimeRight(dbgBean.firstArrival)&&utility.Utility.isTimeRight(dbgBean.firstDep)&& priorDepSite!= siteName)
                        {
                            TimeSpan ts = Convert.ToDateTime(scanTime) - dbgBean.firstDep;
                            if(ts.TotalHours>16)
                            {
                                dbgBean.secondArrival = Convert.ToDateTime(scanTime);
                            }
                            
                        }

                    }

                    if (scanType.Contains("发件"))
                    {
                        if (!arListAllCenters.Contains(siteName) && ((siteName.Contains("转运") || siteName.Contains("分拨"))))
                        {
                            arListAllCenters.Add(siteName);
                        }
                        if (siteName.Contains("转运中心") || siteName.Contains("分拨"))
                        {
                            if(roadBean.dkgx!="")
                            {
                               
                            }
                           
                        }

                    }



                     if (roadBean.status.Contains("派件")&& isCenterAppear)
                    {
                        dbgBean.assignTime= Convert.ToDateTime(scanTime);
                        isAssignAppear = true;
                    }
                    if (scanType.Contains("装车发件") && !isAssignAppear)
                    {
                        if(arListAllSite.Count>0)
                        {
                            dbgBean.actualDepartureTime = Convert.ToDateTime(scanTime);
                            if (!dbgBean.arListDepTimes.Contains(scanTime))
                            {
                                dbgBean.arListDepTimes.Add(scanTime);
                            }
                        }

                        if (!utility.Utility.isTimeRight(dbgBean.firstDep))
                        {
                            bool isNextArrival = true;
                            if (curIndex < arListAllRoadMap.Count - 2)
                            {
                                RoadBean dbgNext = (RoadBean)arListAllRoadMap[curIndex];
                                RoadBean dbgNextNext = (RoadBean)arListAllRoadMap[curIndex + 1];
                                if (dbgNext.scanNetworkName == nextName &&
                                    dbgNext.scanTypeName.Contains("问题件扫描") && dbgNext.waybillTrackingContent.Contains("有发未到件"))
                                {
                                    isNextArrival = false;
                                }
                                if (dbgNext.scanNetworkName != nextName && dbgNextNext.scanNetworkName != nextName)
                                {
                                    isNextArrival = false;
                                }
                            }
                            if(isNextArrival)
                            {
                                dbgBean.firstDep = Convert.ToDateTime(scanTime);
                            }
                            
                        }
                        if (utility.Utility.isTimeRight(dbgBean.firstDep) && utility.Utility.isTimeRight(dbgBean.secondArrival) && priorDepSite != siteName)
                        {
                            bool isNextArrival = true;
                            if(curIndex< arListAllRoadMap.Count-2)
                            {
                                RoadBean dbgNext = (RoadBean)arListAllRoadMap[curIndex];
                                RoadBean dbgNextNext = (RoadBean)arListAllRoadMap[curIndex + 1];
                                if(dbgNext.scanNetworkName==nextName&&
                                    dbgNext.scanTypeName.Contains("问题件扫描") && dbgNext.waybillTrackingContent.Contains("有发未到件"))
                                {
                                    isNextArrival = false;
                                }
                                if(dbgNext.scanNetworkName != nextName&& dbgNextNext.scanNetworkName != nextName)
                                {
                                    isNextArrival = false;
                                }
                            }
                            

                            
                            

                            TimeSpan ts = Convert.ToDateTime(scanTime) - dbgBean.firstDep;
                            if (ts.TotalHours > 16&& isNextArrival)
                            {
                                dbgBean.secondDep = Convert.ToDateTime(scanTime);
                            }

                        }
                        priorDepSite = siteName;
                    }
                    if (!arListAllSite.Contains(siteName))
                    {
                        arListAllSite.Add(siteName);
                    }
                    if(nextName!="")
                    {
                        priorNext = nextName;
                    }
                   
                }
            }
            catch(Exception ex)
            {

            }
        }

        private void handleDutySiteTranferOutDelay(ArrayList arListAllRoadMap, ResultBean resultBean,out bool isMachinSortWrong)
        {
            isMachinSortWrong = false;
            try
            {
                if(resultBean.errorMsg.Contains("未及时转出"))
                {
                    return;
                }
                Hashtable htSortWrongArrival = new Hashtable();

                Hashtable htTransferOut = new Hashtable();
                string sortWrongSite = resultBean.sortErrorSite;
                string firstScanToNet = "";
                string firstScanArrival = "";
                string firstTransferOut = "";
                if(resultBean.sortErrorSite=="")
                {
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        if(roadBean.scanNetworkName== resultBean.dutySite&& roadBean.scanTypeName.Contains("发件")&& roadBean.nextStopName!=""&& resultBean.sortErrorSite == "")
                        {
                            resultBean.sortErrorSite = roadBean.nextStopName;
                            sortWrongSite= roadBean.nextStopName;
                            break;
                        }
                    }
                }
                Hashtable htCenterOperator = new Hashtable();
                bool isFindDepToSortErrorSite = false;
                foreach (RoadBean roadBean in arListAllRoadMap)
                {
                    if(roadBean.scanTypeName.Contains("建包")&& (roadBean.scanNetworkName.Contains("中心")|| roadBean.scanNetworkName.Contains("分拨")))
                    {
                        if(roadBean.waybillTrackingContent.Contains("交叉带"))
                        {
                            htCenterOperator[roadBean.scanNetworkName] = "交叉带";
                        }
                    }
                    if(roadBean.scanNetworkName== sortWrongSite&& roadBean.scanTypeName.Contains("卸车到件")&& !htSortWrongArrival.ContainsKey(sortWrongSite))
                    {
                        htSortWrongArrival[sortWrongSite] = roadBean.scanTime;
                        firstScanArrival= roadBean.scanTime;
                    }

                    if (roadBean.nextStopName == sortWrongSite && roadBean.scanTypeName.Contains("发件")&& roadBean.scanNetworkName==resultBean.dutySite)
                    {
                        isFindDepToSortErrorSite = true;
                    }
                    if (roadBean.nextStopName == sortWrongSite && roadBean.scanTypeName.Contains("发件") && firstScanToNet=="")
                    {
                        firstScanToNet = roadBean.scanTime;
                    }

                    if (roadBean.nextStopName == resultBean.dutySite && roadBean.scanNetworkName== resultBean.sortErrorSite&&  roadBean.scanTypeName.Contains("发件") && firstTransferOut == "")
                    {
                        firstTransferOut = roadBean.scanTime;
                    }
                }

               


                if(firstScanToNet=="")
                {
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        if(firstScanToNet==""&& roadBean.scanTypeName.Contains("到件")&& roadBean.scanNetworkName== sortWrongSite)
                        {
                            firstScanToNet = roadBean.scanTime;
                        }
                    }
                }
                if(firstTransferOut=="")
                {
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        if (roadBean.scanNetworkName == resultBean.sortErrorSite)
                        {
                            firstTransferOut= roadBean.scanTime;
                        }
                    }
                }
                if(firstScanToNet!=""&& firstScanArrival!="")
                {
                    TimeSpan ts = Convert.ToDateTime(firstScanArrival) - Convert.ToDateTime(firstScanToNet);
                    if(ts.TotalHours>12)
                    {
                        if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(resultBean.dutySite))
                        {
                            Hashtable htCenterSite = LoadBasicHelper.Instance.m_ht_sh_effi[resultBean.dutySite] as Hashtable;
                            if (htCenterSite.ContainsKey(sortWrongSite))
                            {
                                ArrayList arListEffi = htCenterSite[sortWrongSite] as ArrayList;
                                firstScanArrival = UtilityHelp.Instance.getMostRecentArrivaTime(Convert.ToDateTime(firstScanToNet), arListEffi);
                               
                            }
                        }                        
                    }
                    DateTime dtCurArrival = Convert.ToDateTime(firstScanArrival);
                    DateTime dtShouldTransferOut = Convert.ToDateTime(dtCurArrival.ToShortDateString() + " " + "23:59:59");
                    if(dtCurArrival.Hour>12)
                    {
                        //dtShouldTransferOut = dtShouldTransferOut.AddDays(1);
                    }
                    DateTime dtActTransferOut = Convert.ToDateTime(firstTransferOut);
                    if(dtActTransferOut> dtShouldTransferOut&& resultBean.dutySite.Contains("网点"))
                    {
                        TimeSpan tsp = dtActTransferOut - dtShouldTransferOut;
                        resultBean.dutySite = resultBean.sortErrorSite;
                        resultBean.errorMsg = "错分未及时转出";
                        resultBean.errorType= "错分未及时转出";
                        resultBean.delayDays = Math.Ceiling((double)tsp.TotalDays).ToString();

                    }
                }


                if (htCenterOperator.ContainsKey(resultBean.dutySite)&& isFindDepToSortErrorSite)
                {
                    isMachinSortWrong = true;
                    return;
                }


            }
            catch(Exception ex)
            {

            }
        }



        private bool isDutySiteTranferOutDelay(ArrayList arListAllRoadMap, ResultBean resultBean,string sortWrongSite)
        {
            bool isTraferOutDelay = false;
            try
            {
                Hashtable htSortWrongArrival = new Hashtable();

                Hashtable htTransferOut = new Hashtable();
  
                string firstScanToNet = "";
                string firstScanArrival = "";
                string firstTransferOut = "";
                if (sortWrongSite == "")
                {
                    bool dutyAppear = false;
                    
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        if (roadBean.scanNetworkName == resultBean.dutySite && (roadBean.scanTypeName.Contains("到件")|| roadBean.scanTypeName.Contains("发件")))
                        {
                            dutyAppear = true;
                            continue;
                        }
                        if(dutyAppear)
                        {
                            if(roadBean.scanNetworkName.Contains("网点"))
                            {
                                sortWrongSite = roadBean.scanNetworkName;
                                break;
                            }
                        }
                    }
                }

                Hashtable htCenterOperator = new Hashtable();
                bool isFindDepToSortErrorSite = false;
                string taskDepNo = "";
                foreach (RoadBean roadBean in arListAllRoadMap)
                {
                    if (roadBean.scanTypeName.Contains("建包") && (roadBean.scanNetworkName.Contains("中心") || roadBean.scanNetworkName.Contains("分拨")))
                    {
                        if (roadBean.waybillTrackingContent.Contains("交叉带"))
                        {
                            htCenterOperator[roadBean.scanNetworkName] = "交叉带";
                        }
                    }
                    if (roadBean.scanNetworkName == sortWrongSite && roadBean.scanTypeName.Contains("卸车到件") && !htSortWrongArrival.ContainsKey(sortWrongSite))
                    {
                        htSortWrongArrival[sortWrongSite] = roadBean.scanTime;
                        firstScanArrival = roadBean.scanTime;
                    }

                    if (roadBean.nextStopName == sortWrongSite && roadBean.scanTypeName.Contains("发件") && roadBean.scanNetworkName == resultBean.dutySite)
                    {
                        isFindDepToSortErrorSite = true;
                        taskDepNo = roadBean.dkgx;
                        if(taskDepNo=="")
                        {
                            if(roadBean.waybillTrackingContent.Contains("任务编号"))
                            {
                                taskDepNo = roadBean.waybillTrackingContent.Substring(roadBean.waybillTrackingContent.LastIndexOf("【")+1);
                                taskDepNo = taskDepNo.Replace("】", "");
                                taskDepNo = taskDepNo.Trim();
                            }
                        }
                    }
                    if (roadBean.nextStopName == sortWrongSite && roadBean.scanTypeName.Contains("发件") && firstScanToNet == "")
                    {
                        firstScanToNet = roadBean.scanTime;
                    }

                    if (roadBean.nextStopName == resultBean.dutySite && roadBean.scanNetworkName == resultBean.sortErrorSite && roadBean.scanTypeName.Contains("发件") && firstTransferOut == "")
                    {
                        firstTransferOut = roadBean.scanTime;
                    }
                }




                if (firstScanToNet == "")
                {
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        if (firstScanToNet == "" && roadBean.scanTypeName.Contains("到件") && roadBean.scanNetworkName == sortWrongSite)
                        {
                            firstScanToNet = roadBean.scanTime;
                            break;
                        }
                    }
                }
                if (firstTransferOut == "")
                {
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        if (roadBean.scanNetworkName == sortWrongSite)
                        {
                            firstTransferOut = roadBean.scanTime;
                            
                        }
                    }
                }
                if(firstScanArrival==""&& taskDepNo!="")
                {
                    firstScanArrival=UtilityHelp.Instance.getPlanArrivalTimeByTaskNo(taskDepNo);
                }
                if (firstScanToNet != "" && firstScanArrival != "")
                {
                    TimeSpan ts = Convert.ToDateTime(firstScanArrival) - Convert.ToDateTime(firstScanToNet);
                    if (ts.TotalHours > 12)
                    {
                        if (LoadBasicHelper.Instance.m_ht_sh_effi.ContainsKey(resultBean.dutySite))
                        {
                            Hashtable htCenterSite = LoadBasicHelper.Instance.m_ht_sh_effi[resultBean.dutySite] as Hashtable;
                            if (htCenterSite.ContainsKey(sortWrongSite))
                            {
                                ArrayList arListEffi = htCenterSite[sortWrongSite] as ArrayList;
                                firstScanArrival = UtilityHelp.Instance.getMostRecentArrivaTime(Convert.ToDateTime(firstScanToNet), arListEffi);

                            }
                        }
                    }
                    DateTime dtCurArrival = Convert.ToDateTime(firstScanArrival);
                    DateTime dtShouldTransferOut = Convert.ToDateTime(dtCurArrival.ToShortDateString() + " " + "23:59:59");
                    if (dtCurArrival.Hour > 12)
                    {
                        //dtShouldTransferOut = dtShouldTransferOut.AddDays(1);
                    }
                    DateTime dtActTransferOut = Convert.ToDateTime(firstTransferOut);
                    if (dtActTransferOut > dtShouldTransferOut && sortWrongSite.Contains("网点"))
                    {
                        TimeSpan tsp = dtActTransferOut - dtShouldTransferOut;
                        resultBean.dutySite = sortWrongSite;
                        resultBean.errorMsg = "错分未及时转出";
                        resultBean.errorType = "错分未及时转出";
                        resultBean.delayDays = Math.Ceiling((double)tsp.TotalDays).ToString();
                        isTraferOutDelay = true;


                    }
                }


               


            }
            catch (Exception ex)
            {

            }
            return isTraferOutDelay;
        }


        private bool isWaybillSortWrong(ResultBean resultBean,ArrayList arListAllRoadMap,ArrayList arListTaskGX,string dispatchSiteArrival,string dispatchSite,ArrayList arListAllCenter)
        {
            bool res = false;
            
            try
            {
                ArrayList arListSite = new ArrayList();
                string priorFJRoad = "";
                int index = 0;
                Hashtable htDepMap = new Hashtable();
                string assinSite = "";
                string lastCenterOrJsan = "";
                string lastCenter = "";
                bool isChangeAddr = false;
                bool isReturn = false;
                string lanshouSite = "";
                string lastToDepSite = "";
                string assignTime = dispatchSiteArrival;
                int curReturnIndex = 0;
                int changeAddrIndex = 0;
                int roadIndex = 0;
                string firstCenterToSite = "";
                string sortWrongTime = "";
                Hashtable htFirstScanTime = new Hashtable();
                bool isCenterSortWrong = false;
                ArrayList arListAllSite = new ArrayList();
                string reportSite = "";
                Hashtable htCurNextFJTime = new Hashtable();
                Hashtable htDepTime = new Hashtable();
                Hashtable htArrivalTime = new Hashtable();
                bool isTransferWaybill = false;
                string changeAddrSite = "";
                int firstTransferIndex = 0;


                ArrayList arListCurNext = new ArrayList();
                Hashtable htCurNext = new Hashtable();
                foreach (RoadBean roadBean in arListAllRoadMap)
                {
                    
                    roadIndex++;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = "";
                    if (scanType.Contains("问题件"))
                    {
                        resultBean.errorType = "问题件";
                    }
                   
                    if ((scanType == "发件扫描" || scanType.ToString() == "装车发件") && nextName!="")
                    {
                        nextStopName = nextName;
                        lastToDepSite = nextStopName;
                        if(!htCurNextFJTime.ContainsKey(roadBean.scanNetworkName+"-"+nextStopName))
                        {
                            htCurNextFJTime[roadBean.scanNetworkName + "-" + nextStopName] = roadBean.scanTime;
                        }
                        if(!htDepTime.ContainsKey(roadBean.scanNetworkName))
                        {
                            htDepTime[roadBean.scanNetworkName] = roadBean.scanTime;
                        }
                        if(!arListCurNext.Contains(roadBean.scanNetworkName + "@" + nextStopName))
                        {
                            arListCurNext.Add(roadBean.scanNetworkName + "@" + nextStopName);
                        }
                        if(!htCurNext.ContainsKey(roadBean.scanNetworkName + "@" + nextStopName))
                        {
                            htCurNext[roadBean.scanNetworkName + "@" + nextStopName] = roadBean.scanTime;
                        }
                        
                    }
                    arListAllSite.Add(roadBean.scanNetworkName);
                    if (!htFirstScanTime.ContainsKey(roadBean.scanNetworkName) && roadBean.scanTime!="")
                    {
                        htFirstScanTime[roadBean.scanNetworkName] = roadBean.scanTime;
                    }
                    if (scanType.Contains("卸车")|| scanType.Contains("到件"))
                    {
                        if(!htArrivalTime.ContainsKey(roadBean.scanNetworkName))
                        {
                            htArrivalTime[roadBean.scanNetworkName]= roadBean.scanTime;
                        }
                    }
                    if (scanType== "退件扫描")
                    {
                        isReturn = true;
                        curReturnIndex = roadIndex;
                        resultBean.isReturnParcel = true;
                    }
                    if (scanType.Contains("转寄登记"))
                    {
                        
                        if (!isTransferWaybill)
                        {
                            firstTransferIndex = roadIndex;
                        }
                        isTransferWaybill = true;
                        
                    }
                    if (sortWrongTime==""&& scanType== "问题件扫描"&& roadBean.waybillTrackingContent.Contains("错分"))
                    {
                        string priorSortWrong = UtilityHelp.Instance.getPriorCenterSortWrong(roadBean.scanNetworkName, arListAllSite);
                        if (!resultBean.isSegmentError)
                        {
                           
                            
                            if (roadBean.scanNetworkName == dispatchSite)
                            {
                                if(!UtilityHelp.Instance.isCurSiteReturnToPrior(roadBean.scanNetworkName, priorSortWrong, roadIndex, arListAllRoadMap))
                                {
                                    continue;
                                }
                               
                            }

                            resultBean.errorMsg = priorSortWrong + " 错发 导致延误";
                            resultBean.errorType = "错发";
                            resultBean.dutySite = priorSortWrong;
                            resultBean.sortErrorSite = roadBean.scanNetworkName;
                            isCenterSortWrong = true;
                            reportSite = roadBean.scanNetworkName;
                        }
                        else
                        {
                            resultBean.dutySite = priorSortWrong;
                            if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, roadBean.scanNetworkName))
                            {
                                return true;
                            }
                        }
                        
                    }
                    if (roadBean.lanshouSite!="")
                    {
                        lanshouSite = roadBean.lanshouSite;
                    }
                    if(roadBean.status=="派件中")
                    {   
                        assinSite = roadBean.scanNetworkName;
                    }
                    if (roadBean.scanNetworkTypeName.Contains("中心")|| roadBean.scanNetworkName.Contains("集散"))
                    {
                        lastCenterOrJsan = roadBean.scanNetworkName;
                    }
                    if (roadBean.scanNetworkTypeName.Contains("中心") )
                    {
                        lastCenter = roadBean.scanNetworkName;
                    }
                    /*if(roadBean.waybillTrackingContent.Contains("改地址")||roadBean.waybillTrackingContent.Contains("更改派送地址"))
                    {
                        resultBean.dutySite = lastCenterOrJsan;

                        changeAddrSite = roadBean.scanNetworkName;
                        changeAddrIndex = roadIndex;
                        isChangeAddr = true;
                    }*/
                    
                }
                if((lanshouSite== assinSite|| lastToDepSite== lanshouSite)&& !isCenterSortWrong)
                {
                    return false;
                }

                if(isCenterSortWrong&& reportSite!= assinSite)
                {
                    if(htDepTime.ContainsKey(resultBean.dutySite))
                    {
                        firstCenterToSite = htDepTime[resultBean.dutySite].ToString();
                        string assignTm = assignTime;
                        if (assignTm != "" && firstCenterToSite != "")
                        {
                            assignTm = assignTm.Substring(0, assignTm.IndexOf(' '));
                            firstCenterToSite = firstCenterToSite.Substring(0, firstCenterToSite.IndexOf(' '));
                        }
                        if(firstCenterToSite!= assignTm)
                        {
                            return true;
                        }

                    }
                    else
                    {
                        return true;
                    }
                   
                }


                if(isChangeAddr&&changeAddrSite!=assinSite&&!isTransferWaybill)
                {
                    return true;
                }
                //转寄件未及时按正确地址转寄
                if(isTransferWaybill)
                {
                    return false;
                    /*string firstInterCept = "";
                    if(UtilityHelp.Instance.isInterceptMore(out firstInterCept, arListAllRoadMap,firstTransferIndex-1))
                    {
                        resultBean.dutySite = firstInterCept;
                        resultBean.errorMsg = "未及时进行转寄处理";
                        return true;
                    }*/
                }


                

                string priorDep = "";
                roadIndex = 0;
                
                foreach (RoadBean roadBean in arListAllRoadMap)
                {
                    roadIndex++;
                    string scanSiteName = roadBean.scanNetworkName;
                    string nextName = roadBean.nextStopName;
                    string scanType = roadBean.scanTypeName;
                    string nextStopName = "";
                    if (scanType == "发件扫描" || scanType.ToString() == "装车发件")
                    {
                        nextStopName = nextName;
                    }
                    if ((scanType == "发件扫描" || scanType.ToString() == "装车发件") && roadIndex> arListAllRoadMap.Count/3)
                    {
                        if(scanSiteName.Contains("转运中心") || scanSiteName.Contains("分拨") || scanSiteName.Contains("集散"))
                        {
                            if(nextStopName.Contains("网点")&& firstCenterToSite=="")
                            {
                                firstCenterToSite = roadBean.scanTime;
                            }
                        }
                    }
                    if (scanSiteName == "" || nextStopName == "")
                    {
                        continue;
                    }
                    if (nextStopName == assinSite)
                    {
                        priorDep = scanSiteName;
                        continue;
                    }
                    if (scanSiteName == assinSite && nextStopName == priorDep)
                    {
                        //防止退回件
                        bool isRealDelay = true;
                        if(isReturn)
                        {
                            if(roadIndex> curReturnIndex)
                            {
                                isRealDelay = false;
                            }

                        }
                        if (changeAddrIndex>0)
                        {
                            if (roadIndex > changeAddrIndex)
                            {
                                isRealDelay = false;
                            }

                        }
                        if (isRealDelay)
                        {
                            if (!resultBean.isSegmentError)
                            {
                                resultBean.errorMsg = assinSite + " 错发 导致延误";
                                resultBean.dutySite = assinSite;
                                resultBean.errorType = "错发";
                                res = true;
                                break;
                            }
                            else
                            {
                                resultBean.dutySite = assinSite;
                                if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, resultBean.sortErrorSite))
                                {
                                    return true;
                                }
                            }
                                
                        }                        

                    }
                }

                if(!res)
                {
                    if(!isReturn&&UtilityHelp.Instance.isSortToWrongSite(arListAllRoadMap, dispatchSite, lanshouSite, resultBean))
                    {
                        if (!resultBean.isSegmentError)
                        {
                            return true;
                        }
                        else
                        {
                            
                            if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, resultBean.sortErrorSite))
                            {
                                return true;
                            }
                        }

                    }

                    if(!isReturn)
                    {
                        if(UtilityHelp.Instance.isSortWrongSiteAndReturn(arListCurNext,htCurNext, resultBean))
                        {
                            if (!resultBean.isSegmentError)
                            {
                                return true;
                            }
                            else
                            {
                                if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, resultBean.sortErrorSite))
                                {
                                    return true;
                                }
                            }
                                
                            /*if(resultBean.sortErrorSite!=dispatchSite)
                            {
                                return true;
                            }*/

                        }
                    }
                }
                if (!res)
                {
                    //错误类型例如JT5086124650140。A转运中心发往下一个转运中心或者集散点B，但是下一个到件是另一个转运你中心C，C再回退到B
                    int curLine = 0;
                    ArrayList arListAllDepDetails = new ArrayList();
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        curLine++;
                        if (curLine < 4)
                        {
                            continue;
                        }
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string nextStopName = "";
                        if (scanType == "发件扫描" || scanType.ToString() == "装车发件")
                        {
                            nextStopName = nextName;
                            bool findarrival = false;
                            if(arListAllDepDetails.Contains(roadBean.scanNetworkName + "@" + nextStopName))
                            {
                                for(int cur= curLine;cur< arListAllRoadMap.Count-1;cur++)
                                {
                                    RoadBean curRoadBean = (RoadBean)arListAllRoadMap[cur];
                                    if(curRoadBean.scanNetworkName== nextName)
                                    {
                                        findarrival = true;
                                        break;
                                    }

                                }
                                if (findarrival)
                                {
                                    arListAllDepDetails.Add(roadBean.scanNetworkName + "@" + nextStopName);
                                }
                            }
                            else
                            {
                                arListAllDepDetails.Add(roadBean.scanNetworkName + "@" + nextStopName);
                            }
                            
                           
                        }
                        if ((roadBean.scanNetworkName.Contains("转运中心") || roadBean.scanNetworkName.Contains("分拨") || roadBean.scanNetworkName.Contains("集散点")) && nextStopName != "" && !nextStopName.Contains("网点"))
                        {
                            string outSite = "";
                            if (UtilityHelp.Instance.isNextStopNotArrivalButAppearNext(arListAllDepDetails,out outSite))
                            {
                                //防止退回件
                                bool isRealDelay = true;
                                if (isReturn)
                                {
                                    if (curLine > curReturnIndex)
                                    {
                                        isRealDelay = false;
                                    }

                                }
                                if (changeAddrIndex > 0)
                                {
                                    if (roadIndex > changeAddrIndex)
                                    {
                                        isRealDelay = false;
                                    }

                                }
                                if (isRealDelay)
                                {
                                    if(!resultBean.isSegmentError)
                                    {
                                        resultBean.errorMsg = outSite + " 错发" + " 导致延误";
                                        resultBean.dutySite = outSite;
                                        resultBean.errorType = "错发";
                                        res = true;
                                    }
                                    
                                }
                            }



                        }
                    }
                }

                //针对转运发到集散点，但是集散点未到货，下一个路由则是网点发往此集散，且集散再发往另外一个不同的网点 JT5087926064029
                if (!res)
                {
                    priorDep = "";
                    roadIndex = 0;
                    ArrayList arListDepToAssign = new ArrayList();
                    bool isAssignAppear = false;
                    Hashtable htWrongSign = new Hashtable();
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        roadIndex++;
                        string scanSiteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string nextStopName = "";
                        if (scanType == "发件扫描" || scanType.ToString() == "装车发件")
                        {
                            nextStopName = nextName;
                        }
                        if (scanType == "发件扫描" || scanType.ToString() == "装车发件")
                        {
                            if (scanSiteName.Contains("转运中心") || scanSiteName.Contains("分拨") || scanSiteName.Contains("集散"))
                            {
                                ArrayList arListDifferentSite = new ArrayList();
                                if((nextStopName.Contains("转运中心")|| nextStopName.Contains("分拨")) &&!arListAllCenter.Contains(nextStopName))
                                {
                                    continue;
                                }

                                if(UtilityHelp.Instance.isNextStopSortWrong(arListAllRoadMap, roadIndex, scanSiteName, nextStopName, arListDifferentSite))
                                {

                                    firstCenterToSite = roadBean.scanTime;

                                    //防止退回件
                                    bool isRealDelay = true;


                                    if (isReturn)
                                    {
                                        if (roadIndex > curReturnIndex)
                                        {
                                            isRealDelay = false;
                                        }

                                    }
                                    if (changeAddrIndex > 0)
                                    {
                                        if (roadIndex > changeAddrIndex)
                                        {
                                            isRealDelay = false;
                                        }

                                    }
                                    if (isRealDelay)
                                    {
                                        int countJS = 0;
                                        int countNet = 0;
                                        foreach(string site in arListDifferentSite)
                                        {
                                            if(site.Contains("网点"))
                                            {
                                                countNet++;
                                            }
                                            if (site.Contains("集散"))
                                            {
                                                countJS++;
                                            }
                                        }
                                        if(countNet<=1&& countJS<=1&& countJS>0)
                                        {
                                            scanSiteName = nextStopName;
                                        }
                                        if(!UtilityHelp.Instance.isMistakeReport(scanSiteName, nextStopName,arListAllCenter))
                                        {
                                            if (!resultBean.isSegmentError)
                                            {
                                                resultBean.errorMsg = scanSiteName + " 错发" + nextStopName + " 导致延误";
                                                resultBean.dutySite = scanSiteName;
                                                resultBean.errorType = "错发";
                                                resultBean.sortErrorSite = nextStopName;
                                                res = true;
                                                break;
                                            }
                                            else
                                            {
                                                if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, nextStopName))
                                                {
                                                    return true;
                                                }
                                            }

                                        }
                                        
                                    }

                                    break;
                                }
                            }
                           
                        }
                        
                        
                        
                    }
                }



                //针对转运或者集散发到最终网点2次以上，但是网点没有回发转运中心这种错误，类似：JT5087361221292
                if (!res)
                {
                    priorDep = "";
                    roadIndex = 0;
                    ArrayList arListDepToAssign = new ArrayList();
                    bool isAssignAppear = false;
                    ArrayList arListSourceSite = new ArrayList();
                    int firstSendToAssignsite = 0;
                    int beginIndex = 0;
                    int endIndex = 0;
                    string depCenterToSite = "";
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        roadIndex++;
                        string scanSiteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string nextStopName = "";
                        if (scanType == "发件扫描"|| scanType.ToString() == "装车发件")
                        {
                            nextStopName = nextName;
                        }
                        if ((scanType == "发件扫描"|| scanType.ToString() == "装车发件") && roadIndex > arListAllRoadMap.Count / 3)
                        {
                            if (scanSiteName.Contains("转运中心") || scanSiteName.Contains("分拨") || scanSiteName.Contains("集散"))
                            {
                                if (nextStopName.Contains("网点") && firstCenterToSite == "")
                                {
                                    firstCenterToSite = roadBean.scanTime;
                                }
                                
                                
                            }
                            if(nextStopName==assinSite&& !isAssignAppear)
                            {
                                if(arListDepToAssign.Count==0)
                                {
                                    arListDepToAssign.Add(roadBean.scanTime);
                                }
                                else
                                {
                                    string prior = arListDepToAssign[0].ToString() ;
                                    if(Convert.ToDateTime(prior).ToShortDateString()!=Convert.ToDateTime(roadBean.scanTime).ToShortDateString())
                                    {
                                        arListDepToAssign.Add(roadBean.scanTime);
                                    }
                                }
                               
                                arListSourceSite.Add(roadBean.scanNetworkName);
                                if(firstSendToAssignsite==0)
                                {
                                    firstSendToAssignsite = roadIndex;
                                }
                                if(arListDepToAssign.Count==1)
                                {
                                    beginIndex = roadIndex;
                                    depCenterToSite = roadBean.scanNetworkName;
                                }
                                else
                                {
                                    endIndex = roadIndex-1;
                                }
                               


                            }
                        }
                        if (roadBean.status == "派件中")
                        {
                            isAssignAppear = true;
                        }
                        if (scanSiteName == "" || nextStopName == "")
                        {
                            continue;
                        }
                        if (nextStopName == assinSite)
                        {
                            priorDep = scanSiteName;
                            //continue;
                        }
                        if (arListDepToAssign.Count==2)
                        {
                            //防止退回件
                            bool isRealDelay = true;
                            if (UtilityHelp.Instance.isScaleAndScanMachineSort(firstSendToAssignsite, arListAllRoadMap, assinSite))
                            {
                                isRealDelay = false;
                            }
                            
                            string firstDepTime = arListDepToAssign[0].ToString();
                            string lastDepTime = arListDepToAssign[arListDepToAssign.Count-1].ToString();
                            if(firstDepTime.Substring(0, firstDepTime.IndexOf(' '))== lastDepTime.Substring(0, lastDepTime.IndexOf(' ')))
                            {
                                isRealDelay = false;
                            }
                            else
                            {
                                firstCenterToSite = firstDepTime;
                            }

                            if (isReturn)
                            {
                                if (roadIndex > curReturnIndex)
                                {
                                    isRealDelay = false;
                                }

                            }
                            if (changeAddrIndex > 0)
                            {
                                if (roadIndex > changeAddrIndex)
                                {
                                    isRealDelay = false;
                                }

                            }
                            if (isRealDelay&&UtilityHelp.Instance.isNextStopArrived(depCenterToSite,arListAllRoadMap, beginIndex, endIndex))
                            {
                                if(!UtilityHelp.Instance.isTerminalSameWtihDispatch(arListAllRoadMap, beginIndex, endIndex))
                                {
                                    if(!resultBean.isSegmentError)
                                    {
                                        resultBean.errorMsg = depCenterToSite + " 错发 导致延误";
                                        resultBean.dutySite = depCenterToSite;
                                        resultBean.errorType = "错发";
                                        res = true;
                                        break;
                                    }
                                    
                                }
                               
                            }

                        }
                    }
                }

                priorDep = "";
                Hashtable htPreDep = new Hashtable();
                bool hasArriveAssinSite = false;
                roadIndex = 0;
                if(!res)
                {
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        roadIndex++;
                        string scanSiteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string nextStopName = "";
                        if (scanType == "发件扫描" || scanType.ToString() == "装车发件")
                        {
                            nextStopName = nextName;
                        }
                        if (scanSiteName == assinSite&& !scanType.Contains("问题件"))
                        {
                            hasArriveAssinSite = true;
                        }

                        if (nextStopName == assinSite && htPreDep.Count == 0)
                        {
                            priorDep = scanSiteName;
                            htPreDep[priorDep] = 1;
                            continue;
                        }

                        if (hasArriveAssinSite && scanSiteName == priorDep && nextStopName == assinSite)
                        {
                            string curSiteScanTime = "";
                            if (roadBean.scanTime != "")
                            {
                                curSiteScanTime = roadBean.scanTime;
                                curSiteScanTime = curSiteScanTime.Substring(0, curSiteScanTime.IndexOf(' '));
                            }
                            string lastAssigh = assignTime;
                            if (lastAssigh.Contains(":"))
                            {
                                lastAssigh = lastAssigh.Substring(0, lastAssigh.IndexOf(' '));
                            }
                            if (lastAssigh != curSiteScanTime)
                            {
                                //防止退回件
                                bool isRealDelay = true;
                                if (isReturn)
                                {
                                    if (roadIndex > curReturnIndex)
                                    {
                                        isRealDelay = false;
                                    }

                                }
                                if (changeAddrIndex > 0)
                                {
                                    if (roadIndex > changeAddrIndex)
                                    {
                                        isRealDelay = false;
                                    }

                                }
                                if (isRealDelay)
                                {
                                    if(!resultBean.isSegmentError)
                                    {
                                        resultBean.errorMsg = assinSite + " 错发 导致延误";
                                        resultBean.dutySite = assinSite;
                                        resultBean.errorType = "错发";
                                        res = true;
                                        break;
                                    }
                                    
                                }

                            }

                        }

                    }
                }
                



                index = 0;
                roadIndex = 0;
                ArrayList arlistAllSendSite = new ArrayList();

                if (!res)
                {
                    //错误类型例如JT5088236643138。转运中心发集散，但是集散未到件记录，而是问题扫描件，下一个到件记录是兰州金港城网点
                    //且转运中心在后续有继续到件的记录
                    int curLine = 0;
                    string priorFJStie = "";
                    string nextShouldSite = "";
                    Hashtable htFirstSendSite = new Hashtable();

                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        curLine++;
                        if (curLine < 5)
                        {
                            continue;
                        }
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string nextStopName = "";


                        if (scanType == "发件扫描" || scanType.ToString() == "装车发件")
                        {
                            nextStopName = nextName;
                            nextShouldSite = nextStopName;
                            if (!htFirstSendSite.ContainsKey(roadBean.scanNetworkName))
                            {
                                htFirstSendSite[roadBean.scanNetworkName] = roadBean.scanTime;
                            }
                            priorFJStie = roadBean.scanNetworkName;
                        }
                        if ((scanType == "卸车扫描" || scanType == "到件扫描" || scanType == "卸车到件") && roadBean.scanNetworkName != nextShouldSite&&nextShouldSite!="")
                        {
                            if (UtilityHelp.Instance.isPriorSendSiteAppearAgain(priorFJStie, arListAllRoadMap, curLine))
                            {
                                //防止退回件
                                bool isRealDelay = true;
                                if (isReturn)
                                {
                                    if (curLine > curReturnIndex)
                                    {
                                        isRealDelay = false;
                                    }

                                }
                                if (changeAddrIndex > 0)
                                {
                                    if (roadIndex > changeAddrIndex)
                                    {
                                        isRealDelay = false;
                                    }

                                }
                                if (isRealDelay)
                                {
                                    if(!resultBean.isSegmentError)
                                    {
                                        resultBean.errorMsg = priorFJStie + " 错发" + roadBean.scanNetworkName + " 导致延误";
                                        resultBean.dutySite = priorFJStie;
                                        resultBean.errorType = "错发";
                                        resultBean.sortErrorSite = roadBean.scanNetworkName;
                                        res = true;
                                        if (htFirstSendSite.ContainsKey(priorFJStie))
                                        {
                                            firstCenterToSite = htFirstSendSite[priorFJStie].ToString();
                                        }
                                    }
                                    else
                                    {
                                        if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, roadBean.scanNetworkName))
                                        {
                                            return true;
                                        }
                                    }


                                }
                                break;
                            }
                        }

                    }
                }



                if (!res)
                {
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        roadIndex++;
                        index++;
                        string scanSiteName = roadBean.scanNetworkName;
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string nextStopName = "";
                        if (scanType == "发件扫描"||scanType.ToString() == "装车发件")
                        {
                            nextStopName = nextName;

                            bool findarrival = false;
                            if (arlistAllSendSite.Contains(scanSiteName))
                            {
                                for (int cur = roadIndex; cur < arListAllRoadMap.Count - 1; cur++)
                                {
                                    RoadBean curRoadBean = (RoadBean)arListAllRoadMap[cur];
                                    if (curRoadBean.scanNetworkName == nextName)
                                    {
                                        findarrival = true;
                                        break;
                                    }

                                }
                                if (findarrival)
                                {
                                    arlistAllSendSite.Add(scanSiteName);
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                arlistAllSendSite.Add(scanSiteName);
                            }

                           
                        }
                        if (scanSiteName == "")
                        {
                            continue;
                        }
                        if (nextStopName != "")
                        {

                            if (!htDepMap.ContainsKey(scanSiteName))
                            {
                                htDepMap[scanSiteName] = nextStopName;
                            }
                            else
                            {
                                string lastSendSite = "";
                                if (arlistAllSendSite.Count > 0)
                                {
                                    lastSendSite = arlistAllSendSite[arlistAllSendSite.Count - 1].ToString();
                                }
                                string pNextStop = htDepMap[scanSiteName] as string;
                                if (pNextStop != nextStopName && !arListSite.Contains(pNextStop) && lastSendSite != scanSiteName)
                                {
                                    //防止退回件
                                    bool isRealDelay = true;
                                    if (isReturn)
                                    {
                                        if (roadIndex > curReturnIndex)
                                        {
                                            isRealDelay = false;
                                        }

                                    }
                                    if (changeAddrIndex > 0)
                                    {
                                        if (roadIndex > changeAddrIndex)
                                        {
                                            isRealDelay = false;
                                        }

                                    }
                                    if (isReturn)
                                    {
                                        if (!resultBean.isSegmentError)
                                        {
                                            resultBean.errorMsg = scanSiteName + " 错发" + pNextStop + " 导致延误";
                                            resultBean.dutySite = scanSiteName;
                                            resultBean.errorType = "错发";
                                            resultBean.sortErrorSite = pNextStop;
                                            res = true;
                                            break;
                                        }
                                        else
                                        {
                                            if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, pNextStop))
                                            {
                                                return true;
                                            }
                                        }

                                    }

                                }
                                else
                                {

                                    if (pNextStop == nextStopName && nextStopName == assinSite && lastSendSite != scanSiteName)
                                    {
                                        //防止退回件
                                        bool isRealDelay = true;
                                        if (isReturn)
                                        {
                                            if (roadIndex > curReturnIndex)
                                            {
                                                isRealDelay = false;
                                            }

                                        }
                                        if (changeAddrIndex > 0)
                                        {
                                            if (roadIndex > changeAddrIndex)
                                            {
                                                isRealDelay = false;
                                            }

                                        }
                                        if (isRealDelay)
                                        {
                                            resultBean.errorMsg = nextStopName + " 错发" + " 导致延误";
                                            resultBean.dutySite = nextStopName;
                                            resultBean.errorType = "错发";
                                            res = true;
                                            break;
                                        }

                                    }
                                }
                            }
                        }

                        if (!arListSite.Contains(scanSiteName))
                        {
                            arListSite.Add(scanSiteName);
                        }
                        else
                        {
                            if (arListSite.IndexOf(scanSiteName) == arListSite.Count - 1)
                            {
                                continue;
                            }
                            else
                            {
                                string priorDesSite = arListSite[arListSite.IndexOf(scanSiteName) + 1].ToString();
                                priorFJRoad = scanSiteName + "-" + priorDesSite;
                                string nextFJRoad = getNextSendSite(arListAllRoadMap, index, scanSiteName);
                                if (!arListSite.Contains(nextFJRoad) && scanSiteName != lanshouSite)
                                {
                                    nextFJRoad = scanSiteName + "-" + nextFJRoad;

                                    if (nextFJRoad != priorFJRoad && !nextFJRoad.EndsWith("-"))
                                    {
                                        if(htCurNextFJTime.ContainsKey(priorFJRoad))
                                        {
                                            firstCenterToSite = htCurNextFJTime[priorFJRoad].ToString();
                                        }
                                        //防止退回件
                                        bool isRealDelay = true;
                                        if (isReturn)
                                        {
                                            if (roadIndex > curReturnIndex)
                                            {
                                                isRealDelay = false;
                                            }

                                        }
                                        if (changeAddrIndex > 0)
                                        {
                                            if (roadIndex > changeAddrIndex)
                                            {
                                                isRealDelay = false;
                                            }

                                        }
                                        if (isRealDelay&& !scanSiteName.Contains(priorDesSite)&&!priorDesSite.Contains(scanSiteName))
                                        {
                                            if (!resultBean.isSegmentError)
                                            {
                                                resultBean.errorMsg = scanSiteName + " 错发" + priorDesSite + " 导致延误";
                                                resultBean.dutySite = scanSiteName;
                                                resultBean.errorType = "错发";
                                                resultBean.sortErrorSite = priorDesSite;
                                                res = true;
                                                break;
                                            }
                                            else
                                            {
                                                resultBean.dutySite = scanSiteName;
                                                if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, priorDesSite))
                                                {
                                                    return true;
                                                }
                                                else
                                                {
                                                    return false;
                                                }
                                            }

                                        }

                                    }
                                }


                            }
                        }

                    }//foreach
                }


                



                if (!res)
                {
                    //错误类型例如JT5086438682631。集散点发往2个不同的网点，且其中一个不是最终签收的网点
                    int curLine = 0;
                
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        curLine++;
                        if(curLine< 5)
                        {
                            continue;
                        }
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string nextStopName = "";
                        if (scanType == "发件扫描"|| scanType.ToString() == "装车发件")
                        {
                            nextStopName = nextName;
                        }
                        if (roadBean.scanNetworkName.Contains("网点")&& nextStopName != ""&& roadBean.scanNetworkName!=assinSite&& roadBean.scanNetworkName!=StoParams.Instance.register_site)
                        {
                            if(nextStopName == lastCenterOrJsan&& curLine>4)
                            {
                                //防止退回件
                                bool isRealDelay = true;
                                if (isReturn)
                                {
                                    if (curLine > curReturnIndex)
                                    {
                                        isRealDelay = false;
                                    }

                                }
                                if (changeAddrIndex > 0)
                                {
                                    if (roadIndex > changeAddrIndex)
                                    {
                                        isRealDelay = false;
                                    }

                                }
                                if (isRealDelay)
                                {
                                    if (!resultBean.isSegmentError)
                                    {
                                        resultBean.errorMsg = lastCenterOrJsan + " 错发" + roadBean.scanNetworkName + " 导致延误";
                                        resultBean.dutySite = lastCenterOrJsan;
                                        resultBean.errorType = "错发";
                                        resultBean.sortErrorSite = roadBean.scanNetworkName;
                                        res = true;
                                    }
                                    else
                                    {
                                        resultBean.dutySite = lastCenterOrJsan;
                                        if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, roadBean.scanNetworkName))
                                        {
                                            return true;
                                        }
                                    }

                                }
                                
                            }

                            
                        }
                    }
                }



                if (!res)
                {
                    //错误类型例如JT5086438682631。集散点发往2个不同的网点，且其中一个不是最终签收的网点
                    int curLine = 0;

                    Hashtable htSendMap = new Hashtable();
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        curLine++;
                        if (curLine < 5)
                        {
                            continue;
                        }
                        string nextName = roadBean.nextStopName;
                        string scanType = roadBean.scanTypeName;
                        string nextStopName = "";
                        if (scanType == "发件扫描" || scanType.ToString() == "装车发件")
                        {
                            nextStopName = nextName;
                        }
                        if (nextName.Contains("网点") && nextStopName != "" && roadBean.scanNetworkName != assinSite && roadBean.scanNetworkName != StoParams.Instance.register_site)
                        {
                            if(!htSendMap.ContainsKey(roadBean.scanNetworkName))
                            {
                                htSendMap[roadBean.scanNetworkName] = nextStopName + "$" + curLine.ToString()+"$" + roadBean.scanTime;
                            }
                            else
                            {
                                string priorLine = htSendMap[roadBean.scanNetworkName] as string;
                                string[] arr = priorLine.Split('$');
                                if(curLine-Convert.ToInt32(arr[1])==1&& nextStopName!= arr[0])
                                {
                                    if(Convert.ToDateTime(arr[2]).ToShortDateString()!= Convert.ToDateTime(roadBean.scanTime).ToShortDateString())
                                    {
                                        if (!resultBean.isSegmentError)
                                        {
                                            resultBean.errorMsg = roadBean.scanNetworkName + " 错发" + arr[0] + " 导致延误";
                                            resultBean.dutySite = roadBean.scanNetworkName;
                                            resultBean.errorType = "错发";
                                            resultBean.sortErrorSite = arr[0];
                                            res = true;
                                        }
                                        else
                                        {
                                            resultBean.dutySite = roadBean.scanNetworkName;
                                            if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, arr[0]))
                                            {
                                                return true;
                                            }
                                        }

                                    }
                                }
                            }
                            
     


                        }
                    }
                }


                if (!res)
                {
                   //todo next
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        if (roadBean.waybillTrackingContent.Contains("错分"))
                        {
                            if (roadBean.scanNetworkName == lastCenterOrJsan)
                            {
                                lastCenterOrJsan = lastCenter;
                            }
                            if (!resultBean.isSegmentError)
                            {
                                if (roadBean.scanNetworkName == dispatchSite)
                                {

                                    continue;
                                }
                                resultBean.errorMsg = lastCenterOrJsan + " 错发" + roadBean.scanNetworkName + " 导致延误";
                                resultBean.dutySite = lastCenterOrJsan;
                                resultBean.errorType = "错发";
                                resultBean.sortErrorSite = roadBean.scanNetworkName;
                                res = true;
                            }
                            else
                            {
                                resultBean.dutySite = lastCenterOrJsan;
                                if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, roadBean.scanNetworkName))
                                {
                                    return true;
                                }
                            }


                        }
                    }
                }



                if (!res)
                {
                   
                    foreach (RoadBean roadBean in arListAllRoadMap)
                    {
                        if(roadBean.waybillTrackingContent.Contains("错分"))
                        {
                            if (roadBean.scanNetworkName == lastCenterOrJsan)
                            {
                                lastCenterOrJsan = lastCenter;
                            }
                            if (!resultBean.isSegmentError)
                            {
                                if(roadBean.scanNetworkName==dispatchSite)
                                {

                                    continue;
                                }
                                resultBean.errorMsg = lastCenterOrJsan + " 错发" + roadBean.scanNetworkName + " 导致延误";
                                resultBean.dutySite = lastCenterOrJsan;
                                resultBean.sortErrorSite = roadBean.scanNetworkName;
                                resultBean.errorType = "错发";
                                res = true;
                            }
                            else
                            {
                                resultBean.dutySite = lastCenterOrJsan;
                                if (isDutySiteTranferOutDelay(arListAllRoadMap, resultBean, roadBean.scanNetworkName))
                                {
                                    return true;
                                }
                            }
                               
                            
                        }
                    }
                }
                string assignDate = assignTime;
                if(res)
                {
                    if(htDepTime.ContainsKey(resultBean.dutySite)&& firstCenterToSite!="")
                    {
                        string dutySiteSendTime = htDepTime[resultBean.dutySite].ToString();
                        string dutyArrivaTime = htArrivalTime[resultBean.dutySite].ToString();
                        if (Convert.ToDateTime(dutySiteSendTime) <Convert.ToDateTime(firstCenterToSite))
                        {
                            firstCenterToSite = dutySiteSendTime;
                        }
                        if(dutyArrivaTime!="")
                        {
                            TimeSpan ts = Convert.ToDateTime(firstCenterToSite) - Convert.ToDateTime(dutyArrivaTime);
                            if(ts.TotalHours>14)
                            {
                                firstCenterToSite = dutyArrivaTime;
                            }
                        }
                    }
                }
                if(assignDate!=""&&firstCenterToSite!="")
                {
                    assignDate = assignDate.Substring(0, assignDate.IndexOf(' '));
                    firstCenterToSite = firstCenterToSite.Substring(0, firstCenterToSite.IndexOf(' '));
                }
                if(firstCenterToSite== assignDate)
                {
                    res = false;
                }


            }
            catch(Exception ex)
            {

            }
            return res;
        }



        public string getNextSendSite(ArrayList arListSites,int index,string curSite)
        {
            string res = "";
            try
            {
                for(int i=index; i< arListSites.Count;i++)
                {
                    RoadBean roadBean = (RoadBean)arListSites[i];
                    if(roadBean.scanNetworkName== curSite)
                    {
                        continue;
                    }
                    else
                    {
                        res = roadBean.scanNetworkName;
                        break;
                    }
                }

            }
            catch(Exception ex)
            {

            }
            return res;
        }

        public bool isSite(string strSiteName)
        {
            bool isSite = true;
            if(strSiteName.Contains("集散")|| strSiteName.Contains("转运中心") || strSiteName.Contains("分拨"))
            {
                isSite = false;
            }
            return isSite;
        }

        public bool isCurSiteArrivalDelay(DateTime jtArrivalSiteTime,DateTime jtShouldArrivalTime,out string delayTime)
        {
            delayTime = "";
            bool isArrivalDelay = false;
            try
            {
                if(jtArrivalSiteTime> jtShouldArrivalTime)
                {
                    isArrivalDelay = true;
                    TimeSpan ts = jtArrivalSiteTime - jtShouldArrivalTime;
                    string outputStr = string.Format("{0}天{1}小时", ts.Days, ts.Hours);
                    delayTime = outputStr.ToString();
                    return isArrivalDelay;
                }
            }
            catch(Exception ex)
            {

            }
            return isArrivalDelay;
        }

        public bool getTimeBeanByTime(string key, TimeSpan tsArrival,out TimeBean timeBean,Hashtable htDbgBeans,string siteCode)
        {
            bool res = false;
            timeBean = new bean.TimeBean();
            try
            {
                DbgBean dbgBean;
                if(htDbgBeans.ContainsKey(siteCode))
                {
                    dbgBean = (DbgBean)htDbgBeans[siteCode];
                    if(dbgBean != null)
                    {
                        if (siteCode == dbgBean.ArrivalNetworkCode)
                        {
                            if (dbgBean.actualArrivalTime < dbgBean.plannedArrivalTime)
                            {
                                tsArrival = new TimeSpan(dbgBean.plannedArrivalTime.Hour, dbgBean.plannedArrivalTime.Minute, 0);
                            }
                            else
                            {
                                tsArrival = new TimeSpan(dbgBean.actualArrivalTime.Hour, dbgBean.actualArrivalTime.Minute, 0);
                            }
                        }

                        if (siteCode == dbgBean.DepNetworkCode)
                        {
                            int a = 0;
                            /*if (dbgBean.actualArrivalTime < dbgBean.plannedArrivalTime)
                            {
                                tsArrival = new TimeSpan(dbgBean.plannedArrivalTime.Hour, dbgBean.plannedArrivalTime.Minute, 0);
                            }
                            else
                            {
                                tsArrival = new TimeSpan(dbgBean.actualArrivalTime.Hour, dbgBean.actualArrivalTime.Minute, 0);
                            }*/
                        }
                    }
                    

                }
                                
                ArrayList arListTimeBeans = JTTimeEffi.Instance.m_ht_effibeans[key] as ArrayList;
                TimeSpan tsMin=new TimeSpan(23,23,23);
                TimeBean curTimeBean = new bean.TimeBean();
                foreach (TimeBean bean in arListTimeBeans)
                {
                    
                    string endTime = bean.endArrival;
                    if (endTime == "")
                    {
                        continue;
                    }
                    int hour = 0;
                    int minute = 0;
                    int seconds = 0;
                    if (!endTime.Contains(":"))
                    {
                        continue;
                    }
                    curTimeBean = bean;
                    utility.Utility.getSepTime(endTime, out hour, out minute);
                    TimeSpan tsEnd = new TimeSpan(hour, minute, seconds);
                    if(tsEnd<tsArrival)
                    {
                        continue;
                    }
                    TimeSpan tsDiff = tsEnd - tsArrival;
                    if(tsDiff<tsMin)
                    {
                        tsMin = tsDiff;
                        timeBean = bean;
                        res = true;
                    }

                }
                if (!res && arListTimeBeans.Count>0)
                {
                    timeBean = curTimeBean;
                }

            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("getTimeBeanByTime ex:"+ex.ToString());
            }
            
            return res;
            
        }


        public int getAssignAddDays(RoadInfo roadSite)
        {
            int addDays = 0;

            try
            {
                string key = roadSite.jtSiteName + "-" + roadSite.jtNextStopName;
                string keyArrCode = "";
                string keyDesCode = "";
                if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadSite.jtSiteName))
                {
                    keyArrCode = JTTimeEffi.Instance.m_ht_site_map[roadSite.jtSiteName] as string;
                }
                if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadSite.jtNextStopName))
                {
                    keyDesCode = JTTimeEffi.Instance.m_ht_site_map[roadSite.jtNextStopName] as string;
                }
                key = keyArrCode + "-" + keyDesCode;
                if(!JTTimeEffi.Instance.m_ht_effibeans.ContainsKey(key))
                {
                    return addDays;
                }
                ArrayList arListTimeBeans = JTTimeEffi.Instance.m_ht_effibeans[key] as ArrayList;

                TimeSpan tsMin = new TimeSpan(23, 23, 23);
                TimeBean curTimeBean = new bean.TimeBean();
                foreach (TimeBean bean in arListTimeBeans)
                {
                    string endTime = bean.endArrival;
                    if (endTime == "")
                    {
                        continue;
                    }
                    int hour = 0;
                    int minute = 0;
                    int seconds = 0;
                    if (!endTime.Contains(":"))
                    {
                        continue;
                    }
                    curTimeBean = bean;
                    addDays = bean.assignAddDays;

                }          

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("getAssignAddDays ex:" + ex.ToString());
            }

            return addDays;

        }


        public bool noMapBingoJudge(RoadInfo roadSite)
        {
            bool isDelay = false;
            try
            {
                DateTime dtArrival = roadSite.jtArrivalTime;
                DateTime dtDep = roadSite.jtDepTime;
                TimeSpan tspan = dtDep - dtArrival;
                if(dtArrival.Year==1)
                {
                    return isDelay;
                }
                if(tspan.Hours>23)
                {
                    isDelay = true;
                    roadSite.jtDelaySite = roadSite.jtSiteName;
                    roadSite.jtDelayTime = tspan.ToString();
                }
            }
            catch(Exception ex)
            {

            }
            return isDelay;
        }

        public bool isCurSiteDepDelay(RoadInfo roadSite, Hashtable htNextSiteShouldArriveTime,out string delayTime,Hashtable htDbgBeans)
        {
            delayTime = "";
            bool isDepDelay = false;
            try
            {
                string key = roadSite.jtSiteName + "-" + roadSite.jtNextStopName;
                string keyArrCode = "";
                string keyDesCode = "";
                if(JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadSite.jtSiteName))
                {
                    keyArrCode = JTTimeEffi.Instance.m_ht_site_map[roadSite.jtSiteName] as string;
                }
                if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadSite.jtNextStopName))
                {
                    keyDesCode = JTTimeEffi.Instance.m_ht_site_map[roadSite.jtNextStopName] as string;
                }
                key = keyArrCode + "-" + keyDesCode;
                if (!JTTimeEffi.Instance.m_ht_effibeans.ContainsKey(key))
                {
                    isDepDelay = noMapBingoJudge(roadSite);
                    return isDepDelay;
                }
                
                DateTime dtArrival = roadSite.jtArrivalTime;
                TimeSpan tsArrival = dtArrival.TimeOfDay;
                
                TimeBean timeBean = new bean.TimeBean();
                /*if(!getTimeBeanByTime(key, tsArrival, out timeBean))
                {
                    return isDepDelay;
                }*/
                getTimeBeanByTime(key, tsArrival, out timeBean, htDbgBeans, keyArrCode);
                int addDays = 0;
                TimeSpan tsEnd = new TimeSpan();
                if(timeBean.endDepart.Contains(":"))
                {
                    string[] arr = timeBean.endDepart.Split(':');
                    tsEnd = new TimeSpan(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]),0);
                    if (tsArrival.CompareTo(tsEnd) > 0)
                    {
                        addDays = 1;
                    }
                }

                
               

                DateTime dtDep = roadSite.jtDepTime;
                TimeSpan tsDep = dtDep.TimeOfDay;
                int hour = 0;
                int minute = 0;
                utility.Utility.getSepTime(timeBean.endDepart, out hour, out minute);
                TimeSpan tsEndDep = new TimeSpan(hour, minute, 0);
          
                string strDate = roadSite.jtArrivalTime.ToShortDateString();
                DateTime dtShouldDep = Convert.ToDateTime(strDate)+ tsEndDep;
                dtShouldDep = dtShouldDep.AddDays(addDays);

                utility.Utility.getSepTime(timeBean.planArriveNextStie, out hour, out minute);
                TimeSpan tsPlanNext = new TimeSpan(hour, minute, 0);
                DateTime dtPlanNextSite = Convert.ToDateTime(strDate).AddDays(timeBean.transferAddDays+ addDays) + tsPlanNext;
                htNextSiteShouldArriveTime[roadSite.jtNextStopName] = dtPlanNextSite;

                if(dtDep>dtShouldDep)
                {
                    TimeSpan tsDiff = dtDep - dtShouldDep;
                    if(tsDiff.TotalMinutes>3)
                    {
                        isDepDelay = true;
                        TimeSpan tsDelays = dtDep - dtShouldDep;
                        string outputStr = string.Format("{0}天{1}小时", tsDelays.Days, tsDelays.Hours);
                        delayTime = outputStr.ToString();
                    }
                   

                    getTimeBeanByTime(key, tsDep, out timeBean,htDbgBeans, keyDesCode);
                    string[] arr = timeBean.endDepart.Split(':');
                    tsEnd = new TimeSpan(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]), 0);
                    if (tsDep.CompareTo(tsEnd) > 0)
                    {
                        addDays = 1;
                    }
                    dtPlanNextSite = Convert.ToDateTime(strDate).AddDays(timeBean.transferAddDays + addDays) + tsPlanNext;
                    htNextSiteShouldArriveTime[roadSite.jtNextStopName] = dtPlanNextSite;

                }

                //TimeSpan tsEnd=

            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isCurSiteDepDelay delay ex:"+ex.ToString());
            }
            return isDepDelay;
        }

        public bool isOverTimeParcel(string barcode, JArray details, RoadInfo roadInfo,Hashtable htdbg)
        {
            bool isOverTime = false;

            for (int i = details.Count - 1; i >= 0; i--)
            {
                JObject jason = (JObject)details[i];
                
                string status = jason["status"].ToString();
                JToken scanNetworkName = jason["scanNetworkName"];
                JToken scanTypeName = jason["scanTypeName"];
                JToken remark2 = jason["remark2"];
                string scanTime = jason["scanTime"].ToString();
                roadInfo.lastScanStatus = status;

                if(scanTypeName != null && scanTypeName.ToString() == "卸车扫描" && remark2 !=null&& remark2.ToString().StartsWith("DBG"))
                {
                    DbgBean dbgBean = new DbgBean();
                    htdbg[remark2.ToString()] = dbgBean;
                }
                if (status == "运送中")
                {
                    continue;
                }
                string waybillTrackingContent = jason["waybillTrackingContent"].ToString();
                if (status == "派件中" && scanTypeName.ToString() == "入库扫描" && roadInfo.yizhanRecTime == "" && waybillTrackingContent.Contains("您的快件已存放至"))
                {
                    roadInfo.yizhanRecTime = scanTime;
                }
                if (status == "已签收" && roadInfo.donePackTime == "")
                {
                    roadInfo.donePackTime = scanTime;
                }
            }
            DateTime dtFinish;
            if (roadInfo.yizhanRecTime!="")
            {
                dtFinish = Convert.ToDateTime(roadInfo.yizhanRecTime);
            }
            else if(roadInfo.donePackTime!="")
            {
                dtFinish = Convert.ToDateTime(roadInfo.donePackTime);
            }
            else
            {
                return isOverTime;
            }
            dtFinish = Convert.ToDateTime(dtFinish.ToShortDateString() + " 00:00:00");
            TimeSpan ts = System.DateTime.Now - dtFinish;
            if(Math.Ceiling(ts.TotalDays) >5)
            {
                isOverTime = true;
            }         
            return isOverTime;
        }

        public bool isSortWrongDelay(string barcode, JArray details, RoadInfo roadInfo, out int res,out bool isReturnParcel,Hashtable htSiteDbgs)
        {
            isReturnParcel = false;
            bool isSortWrong = false;
            res = 0;
            try
            {
                ArrayList arListDetails = new ArrayList();
                int count = 0;
                string siteName = "";
                string tmpSite = "";
                string lastSite = "";
                bool isPacelInYizhan = false;
                Hashtable htCurSiteShouldArrival = new Hashtable();
                Hashtable htCurSiteBean = new Hashtable();
                ArrayList arListRoadSites = new ArrayList();
                RoadInfo priorRoadInfo = new RoadInfo();

                Hashtable htArrivalSite = new Hashtable();
                Hashtable htArrivalTimeSite = new Hashtable();
                ArrayList arListAllDepRoadSite = new ArrayList();
                ArrayList arListAllRoadSites = new ArrayList();
                string assignSite = "";
                for (int i = details.Count - 1; i >= 0; i--)
                {
                    JObject jason = (JObject)details[i];
                    arListDetails.Add(jason);
                    count++;
                    string status = jason["status"].ToString();
                    JToken scanNetworkName = jason["scanNetworkName"];
                    JToken scanTypeName = jason["scanTypeName"];
                    string scanTime = jason["scanTime"].ToString();
                    roadInfo.lastScanStatus = status;

                    RoadInfo curRoad = new RoadInfo();
                    curRoad.lastScanStatus = status;

                    curRoad.jtScanTime = Convert.ToDateTime(scanTime);
                    if(!utility.Utility.IsNullOrEmpty(scanNetworkName))
                    {
                        curRoad.jtSiteName = scanNetworkName.ToString();
                    }
                    arListAllRoadSites.Add(curRoad);
                    if(!utility.Utility.IsNullOrEmpty(status)&& status.ToString()== "派件中")
                    {
                        assignSite= scanNetworkName.ToString(); 
                    }
                    if(!utility.Utility.IsNullOrEmpty(scanNetworkName) && !utility.Utility.IsNullOrEmpty(scanTypeName))
                    {
                        curRoad.jtScanType = scanTypeName.ToString();
                    }

                    if (!utility.Utility.IsNullOrEmpty(scanNetworkName)&& !utility.Utility.IsNullOrEmpty(scanTypeName)
                        && (scanTypeName.ToString() == "发件扫描"|| scanTypeName.ToString() == "装车发件"))
                    {
                        curRoad.jtSiteName = scanNetworkName.ToString() ;
                        JToken nextStopName = jason["nextStopName"];
                        if(!utility.Utility.IsNullOrEmpty(nextStopName))
                        {
                            curRoad.jtNextStopName = nextStopName.ToString();
                        }
                        curRoad.jtDepTime = Convert.ToDateTime(scanTime);
                        arListAllDepRoadSite.Add(curRoad);
                    }

                    if (scanTypeName != null && scanTypeName.ToString() == "问题件扫描")
                    {
                        JToken waybillTrackingContent  = jason["waybillTrackingContent"];
                        if(waybillTrackingContent!=null&& waybillTrackingContent.ToString().Contains("错分"))
                        {
                            isSortWrong = true;
                            DateTime dtPrior =priorRoadInfo.jtDepTime;
                            TimeSpan ts = Convert.ToDateTime(scanTime) - dtPrior;
                            string outputStr = string.Format("{0}天{1}小时", ts.Days, ts.Hours);
                            roadInfo.strErrorMsg = "错分件 " + priorRoadInfo.jtSiteName + " 错发" + scanNetworkName;
                            roadInfo.jtDelaySite = priorRoadInfo.jtSiteName;
                            
                            roadInfo.jtDelayTime = outputStr;
                            //return isSortWrong;
                        }
                        //if()
                    }

                    if (scanTypeName != null && scanTypeName.ToString() == "退件登记")
                    {
                        JToken waybillTrackingContent = jason["waybillTrackingContent"];
                        if (!utility.Utility.IsNullOrEmpty(waybillTrackingContent)&& waybillTrackingContent != null && waybillTrackingContent.ToString().Contains("退回件登记"))
                        {
                            isReturnParcel = true;
                            return isSortWrong;
                        }
                        //if()
                    }

                    

                    if (scanTypeName != null && (scanTypeName.ToString() == "发件扫描"|| scanTypeName.ToString() == "装车发件"))
                    {
                        curRoad.jtDepTime = Convert.ToDateTime(scanTime);
                        JToken nextStopName = jason["nextStopName"];
                        if (nextStopName != null)
                        {
                            
                            tmpSite = nextStopName.ToString();
                            curRoad.jtNextStopName = tmpSite;
                            string strKey = scanNetworkName.ToString() + "-" + curRoad.jtNextStopName;
                            string revertKey = curRoad.jtNextStopName + "-" + scanNetworkName.ToString();
                            htCurSiteBean[strKey] = Convert.ToDateTime(scanTime);
                            if (htCurSiteBean.ContainsKey(revertKey))
                            {
                                isSortWrong = true;
                                DateTime dtPrior = Convert.ToDateTime(htCurSiteBean[revertKey].ToString());
                                TimeSpan ts = Convert.ToDateTime(scanTime) - dtPrior;
                                string outputStr = string.Format("{0}天{1}小时", ts.Days, ts.Hours);
                                roadInfo.strErrorMsg = "错分件 " + curRoad.jtNextStopName + " 错发" + scanNetworkName;
                                roadInfo.jtDelaySite = curRoad.jtNextStopName;
                                roadInfo.jtDelayTime = outputStr;
                                return isSortWrong;

                            }
                            priorRoadInfo.jtDepTime = Convert.ToDateTime(scanTime);
                            priorRoadInfo.jtSiteName = scanNetworkName.ToString();
                        }
                    }


                    if (!utility.Utility.IsNullOrEmpty(scanTypeName) && scanTypeName != null && scanTypeName.ToString() == "卸车扫描")
                    {
                        curRoad.jtArrivalTime = Convert.ToDateTime(scanTime);
                        
                        if (!htArrivalSite.ContainsKey(scanNetworkName))
                        {
                            htArrivalSite[scanNetworkName] = i;
                            htArrivalTimeSite[scanNetworkName] = scanTime;
                        }
                        else
                        {
                            int priorIndex = Convert.ToInt32(htArrivalSite[scanNetworkName]);
                            if (Math.Abs(priorIndex - i) > 2)
                            {
                                string errorSendSite = "";
                                if (utility.Utility.isSorWrongThisSite(priorIndex, i, details, scanNetworkName.ToString(), out errorSendSite))
                                {
                                    isSortWrong = true;
                                    DateTime dtPrior = Convert.ToDateTime(htArrivalTimeSite[scanNetworkName].ToString());
                                    TimeSpan ts = Convert.ToDateTime(scanTime) - dtPrior;
                                    string outputStr = string.Format("{0}天{1}小时", ts.Days, ts.Hours);
                                    roadInfo.strErrorMsg = "错分件 " + scanNetworkName + " 错发" + errorSendSite;
                                    roadInfo.jtDelaySite = scanNetworkName.ToString();
                                    roadInfo.jtDelayTime = outputStr;
                                    return isSortWrong;
                                }

                            }

                        }
                    }
                }
                Hashtable htDepRoads = new Hashtable();
                DateTime dtErrorScanBegin;
                foreach(RoadInfo curRoad in arListAllDepRoadSite)
                {
                    if(!htDepRoads.ContainsKey(curRoad.jtSiteName))
                    {
                        htDepRoads[curRoad.jtSiteName] = curRoad;
                    }
                    if(htDepRoads.ContainsKey(curRoad.jtNextStopName))
                    {
                        DateTime dtCur = curRoad.jtDepTime;
                        RoadInfo prior = (RoadInfo)htDepRoads[curRoad.jtNextStopName];
                        DateTime dtPrior = prior.jtScanTime;
                        dtErrorScanBegin = dtPrior;
                        TimeSpan ts = dtCur - dtPrior;
                        if(ts.TotalHours>8)
                        {
                            isSortWrong = true;
                            roadInfo.jtDelaySite = curRoad.jtNextStopName;
                            TimeSpan tsDelay= utility.Utility.getDelayTime(arListAllRoadSites, curRoad.jtNextStopName, curRoad.jtSiteName, dtErrorScanBegin);
                            string outputStr = string.Format("{0}天{1}小时", tsDelay.Days, tsDelay.Hours);
                            roadInfo.strErrorMsg = "错分件 " + curRoad.jtNextStopName + " 错发" + curRoad.jtSiteName;
                            roadInfo.jtDelayTime = outputStr;
                            return isSortWrong;
                        }
                    }
                }
                string outStrMsg = "";
                isSortWrong = isSortToDifferetSite(arListAllRoadSites, assignSite, out outStrMsg, htSiteDbgs, roadInfo);
            }
            catch(Exception ex)
            {

            }
            return isSortWrong;
        }


        public bool isSortToDifferetSite(ArrayList arListRoads,string lastSite,out string delayTime,Hashtable htDbgBeans,RoadInfo globalRoad)
        {
            delayTime = "";
            bool isDelay = false;
            try
            {
                bool bingo = false;
                ArrayList arListDifferntSites = new ArrayList();
                bool firstNearSiteBingo = false;
                bool nextNearSiteBingo = false;
                DateTime dtLastSiteArrivaTime=System.DateTime.Now;
                string key = "";
                string keyArrCode = "";
                string keyDesCode = "";
                for (int i= arListRoads.Count-1; i >= 0; i--)
                {
                    RoadInfo roadInfo = (RoadInfo)arListRoads[i];
                    if(lastSite== roadInfo.jtSiteName)
                    {
                        bingo = true;
                        if(roadInfo.jtScanType == "卸车扫描"|| roadInfo.jtScanType == "到件扫描" || roadInfo.jtScanType == "卸车到件")
                        {
                            dtLastSiteArrivaTime = roadInfo.jtScanTime;
                        }
                    }
                    else
                    {
                        if(bingo)
                        {
                            if(!arListDifferntSites.Contains(roadInfo.jtSiteName))
                            {
                                arListDifferntSites.Add(roadInfo.jtSiteName);
                            }
                            
                            string curSite = roadInfo.jtSiteName;
                            
                            if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(roadInfo.jtSiteName))
                            {
                                keyArrCode = JTTimeEffi.Instance.m_ht_site_map[roadInfo.jtSiteName] as string;
                            }
                            if (JTTimeEffi.Instance.m_ht_site_map.ContainsKey(lastSite))
                            {
                                keyDesCode = JTTimeEffi.Instance.m_ht_site_map[lastSite] as string;
                            }
                            key = keyArrCode + "-" + keyDesCode;
                            if (arListDifferntSites.Count==1)
                            {                               
                                if (JTTimeEffi.Instance.m_ht_effibeans.ContainsKey(key))
                                {
                                    firstNearSiteBingo = true;
                                    return isDelay;
                                }
                            }
                            else if(arListDifferntSites.Count >= 2)
                            {
                                if (JTTimeEffi.Instance.m_ht_effibeans.ContainsKey(key))
                                {
                                    nextNearSiteBingo = true;
                                    break;
                                }

                            }

                        }
                    }
                }

          
                if (nextNearSiteBingo&&!firstNearSiteBingo)
                {
                    isDelay = true;
                    string sortToWrongSite = arListDifferntSites[0].ToString();
                    string sortWrongCenter= arListDifferntSites[1].ToString();
                    DateTime dtArrivalCenter=System.DateTime.Now;
                    foreach (RoadInfo roadInfo in arListRoads)
                    {
                        if (roadInfo.jtSiteName == arListDifferntSites[1].ToString() && roadInfo.jtScanType == "卸车扫描")
                        {
                            dtArrivalCenter = roadInfo.jtScanTime;
                            break;
                        }                       
                    }


                    TimeBean timeBean = new bean.TimeBean();
                    TimeSpan tsArrival = dtArrivalCenter.TimeOfDay;
                    getTimeBeanByTime(key, tsArrival, out timeBean, htDbgBeans, keyArrCode);
                    int addDays = 0;
                    TimeSpan tsEnd = new TimeSpan();
                    if (timeBean.endDepart.Contains(":"))
                    {
                        string[] arr = timeBean.endDepart.Split(':');
                        tsEnd = new TimeSpan(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]), 0);
                        if (tsArrival.CompareTo(tsEnd) > 0)
                        {
                            addDays = 1;
                        }
                    }

                    //DateTime dtDep = roadSite.jtDepTime;
                    //TimeSpan tsDep = dtDep.TimeOfDay;
                    int hour = 0;
                    int minute = 0;
                    /*utility.Utility.getSepTime(timeBean.endDepart, out hour, out minute);
                    TimeSpan tsEndDep = new TimeSpan(hour, minute, 0);

                    string strDate = dtArrivalCenter.ToShortDateString();
                    DateTime dtShouldDep = Convert.ToDateTime(strDate) + tsEndDep;
                    dtShouldDep = dtShouldDep.AddDays(addDays);*/
                    string strDate = dtArrivalCenter.ToShortDateString();
                    utility.Utility.getSepTime(timeBean.planArriveNextStie, out hour, out minute);
                    TimeSpan tsPlanNext = new TimeSpan(hour, minute, 0);
                    DateTime dtPlanNextSite = Convert.ToDateTime(strDate).AddDays(timeBean.transferAddDays + addDays) + tsPlanNext;
                    TimeSpan tsdelay = dtLastSiteArrivaTime - dtPlanNextSite;
                    string outputStr = string.Format("{0}天{1}小时", tsdelay.Days, tsdelay.Hours);
                    globalRoad.strErrorMsg = "错分件 " + arListDifferntSites[1].ToString() + " 错发" + arListDifferntSites[0].ToString();
                    globalRoad.jtDelaySite = arListDifferntSites[1].ToString();
                    globalRoad.jtDelayTime = outputStr;

                }
            }
            catch(Exception ex)
            {

            }
            return isDelay;
        }


        public bool isTransferDelay(string barcode, JArray details, RoadInfo roadInfo, out int res,Hashtable htDbgs)
        {
            int rowIndex = 0;
            res = 0;
            bool isDelay = false;
            try
            {
                ArrayList arListDetails = new ArrayList();
                int count = 0;
                string siteName = "";
                string tmpSite = "";
                string lastSite = "";
                bool isPacelInYizhan = false;
                Hashtable htCurSiteShouldArrival = new Hashtable();
                Hashtable htCurSiteBean = new Hashtable();
                ArrayList arListRoadSites = new ArrayList();
                for (int i = details.Count - 1; i >= 0; i--)
                {                   
                    JObject jason = (JObject)details[i];
                    arListDetails.Add(jason);
                    count++;
                    string status = jason["status"].ToString();
                    JToken scanNetworkName = jason["scanNetworkName"];
                    JToken scanTypeName = jason["scanTypeName"];
                    string scanTime = jason["scanTime"].ToString();
                    roadInfo.lastScanStatus = status;
                    if (status != "运送中")
                    {
                        continue;
                    }
                    RoadInfo curRoad= new RoadInfo();
                    if (scanNetworkName != null)
                    {
                        lastSite = scanNetworkName.ToString();
                        if(!arListRoadSites.Contains(scanNetworkName.ToString()))
                        {
                            arListRoadSites.Add(scanNetworkName.ToString());
                        }
                        if(!htCurSiteBean.ContainsKey(scanNetworkName.ToString()))
                        {
                            curRoad = new RoadInfo();
                            curRoad.jtSiteName = scanNetworkName.ToString();
                            htCurSiteBean[scanNetworkName.ToString()] = curRoad;
                        }
                        else
                        {
                            curRoad = htCurSiteBean[scanNetworkName.ToString()] as RoadInfo;
                        }
                    }
                    if (scanTypeName != null && (scanTypeName.ToString() == "发件扫描"|| scanTypeName.ToString() == "装车发件"))
                    {
                        curRoad.jtDepTime = Convert.ToDateTime(scanTime);
                        JToken nextStopName = jason["nextStopName"];
                        if (nextStopName != null)
                        {
                            tmpSite = nextStopName.ToString();
                            curRoad.jtNextStopName = tmpSite;
                        }
                    }
                    if (scanTypeName != null && scanTypeName.ToString().Contains("到件"))
                    {
                        curRoad.jtArrivalTime = Convert.ToDateTime(scanTime);
                    }

                }
                if (siteName == "" && isSite(tmpSite))
                {
                    siteName = tmpSite;
                }
                roadInfo.lastSiteName = siteName;
                if (roadInfo.lastSiteName == "")
                {
                    roadInfo.lastSiteName = lastSite;
                }
                Hashtable htNextSiteSholdArrival = new Hashtable();
                string strDelayTime = "";
                foreach(string strSite in arListRoadSites)
                {
                    bool isDepSiteDelay = false;
                    bool isArrSiteDelay = false;
                    if (htCurSiteBean.ContainsKey(strSite))
                    {
                        RoadInfo roadSite = htCurSiteBean[strSite] as RoadInfo;
                        if(roadSite.jtNextStopName!="")
                        {                           
                            if(isCurSiteDepDelay(roadSite, htNextSiteSholdArrival,out strDelayTime, htDbgs))
                            {
                                
                                if(utility.Utility.isDelayMore(roadInfo.jtDelayTime, strDelayTime))
                                {
                                  
                                    if(!isSite(strSite))
                                    {
                                        isDelay = true;
                                        roadInfo.jtDelaySite = strSite;
                                        roadInfo.jtDelayTime = strDelayTime;
                                        roadInfo.jtDepDelayTime = strDelayTime;
                                        roadInfo.strErrorMsg = "" + strSite + " 到件:" + roadSite.jtArrivalTime + " " + " 发件：" + roadSite.jtDepTime + "";
                                        isDepSiteDelay = true;
                                    }
                                    
                                }
                                
                            }

                        }
                    }
                }
                string priorSite = "";
                foreach (string strSite in arListRoadSites)
                {
                    RoadInfo roadSite = htCurSiteBean[strSite] as RoadInfo;
                    if (htNextSiteSholdArrival.ContainsKey(strSite))
                    {
                        DateTime dtNextSiteArrivalTime = (DateTime)htNextSiteSholdArrival[strSite];
                        int addAssingDays = getAssignAddDays(roadSite);
                        dtNextSiteArrivalTime = dtNextSiteArrivalTime.AddDays(addAssingDays);
                        if (isCurSiteArrivalDelay(roadSite.jtArrivalTime, dtNextSiteArrivalTime, out strDelayTime))
                        {
                            if (utility.Utility.isDelayMore(roadInfo.jtDelayTime, strDelayTime))
                            {
                                if (!isSite(strSite))
                                {
                                    RoadInfo preSite = htCurSiteBean[priorSite] as RoadInfo;
                                    isDelay = true;
                                    roadInfo.jtDelaySite = strSite;
                                    roadInfo.strErrorMsg = "" + preSite.jtSiteName + " 发件:" + preSite.jtDepTime + " " + strSite + " 到件：" + roadSite.jtArrivalTime + "";
                                    roadInfo.jtDelayTime = strDelayTime;
                                }
                                    
                            }
                                
                            //return isDelay;
                        }
                    }
                    priorSite = strSite;
                }

                    /*foreach (JObject json in arListDetails)
                    {
                        string scanTypeName = json["scanTypeName"].ToString();
                        string scanTime = json["scanTime"].ToString();
                        string scanNetworkName = "";
                        JToken scanSite = json["scanNetworkName"];
                        if (scanSite != null)
                        {
                            scanNetworkName = scanSite.ToString();
                        }
                        roadInfo.lastSacnTime = scanTime;
                        string status = json["status"].ToString();

                        string waybillTrackingContent = json["waybillTrackingContent"].ToString();
                        int code = Convert.ToInt32(json["code"].ToString());
                        if (rowIndex < 2 && scanTypeName == "快件揽收" && code == 10)
                        {
                            roadInfo.lanshouTime = scanTime;
                        }
                        if (status == "已签收" && roadInfo.donePackTime == "")
                        {
                            roadInfo.donePackTime = scanTime;
                        }
                        if (scanNetworkName == siteName)
                        {
                            if (scanTypeName == "到件扫描")
                            {
                                roadInfo.arriveSiteTime = scanTime;
                            }
                            if (status == "派件中" && scanTypeName == "出仓扫描" && roadInfo.assignPackTime == "")
                            {
                                roadInfo.assignPackTime = scanTime;
                            }
                            if (status == "派件中" && scanTypeName == "入库扫描" && roadInfo.yizhanRecTime == "" && waybillTrackingContent.Contains("您的快件已存放至"))
                            {
                                roadInfo.yizhanRecTime = scanTime;
                                if (roadInfo.donePackTime != "" && Convert.ToDateTime(roadInfo.donePackTime) < Convert.ToDateTime(scanTime))
                                {
                                    roadInfo.strErrorMsg = "签收后又入驿站";
                                    isDelay = true;
                                    break;
                                }
                            }
                            if (status == "派件中" && scanTypeName == "入库扫描" && !waybillTrackingContent.Contains("您的快件已存放至"))
                            {
                                isPacelInYizhan = true;
                            }
                        }

                        rowIndex++;

                    }*/
                    //isDelay = (isAssignDelay(roadInfo) || isYizhanDelay(roadInfo) || isLostParcel(roadInfo));


            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isParcelDelay ex:" + ex.ToString() + " rowIndex=" + rowIndex.ToString());
            }
            return isDelay;
        }



        public bool isParcelDelay(string barcode, JArray details, RoadInfo roadInfo,out int res)
        {
            int rowIndex = 0;
            res = 0;
            bool isDelay = false;
            try
            {
                ArrayList arListDetails = new ArrayList();
                int count = 0;
                string siteName = "";
                string tmpSite = "";
                string lastSite = "";
                bool isPacelInYizhan = false;
                for(int i= details.Count-1;i>=0;i--)
                {
                    
                    JObject jason = (JObject)details[i];
                    arListDetails.Add(jason);
                    count++;
                    string status = jason["status"].ToString();
                    JToken scanNetworkName = jason["scanNetworkName"];
                    JToken scanTypeName = jason["scanTypeName"];
                    roadInfo.lastScanStatus = status;
                   
                    if(scanNetworkName!=null)
                    {
                        lastSite = scanNetworkName.ToString();
                    }
                    if (scanNetworkName!=null&&siteName == ""&& status== "派件中")
                    {                        
                        siteName = scanNetworkName.ToString();
                    }
                    if(scanTypeName!=null&& (scanTypeName.ToString()== "发件扫描"|| scanTypeName.ToString() == "装车发件"))
                    {
                        JToken nextStopName = jason["nextStopName"];
                        if(nextStopName!=null)
                        {
                            tmpSite = nextStopName.ToString();
                        }                        
                    }
                }
                if(siteName==""&&isSite(tmpSite))
                {
                    siteName = tmpSite;
                }
                roadInfo.lastSiteName = siteName; 
                if(roadInfo.lastSiteName=="")
                {
                    roadInfo.lastSiteName = lastSite;
                }             

                foreach (JObject json in arListDetails)
                {
                    string scanTypeName = json["scanTypeName"].ToString();
                    string scanTime = json["scanTime"].ToString();
                    string scanNetworkName= "";
                    JToken scanSite = json["scanNetworkName"];
                    if(scanSite!=null)
                    {
                        scanNetworkName = scanSite.ToString();
                    }
                    roadInfo.lastSacnTime = scanTime;
                    string status = json["status"].ToString();
                    
                    string waybillTrackingContent = json["waybillTrackingContent"].ToString();
                    int code = Convert.ToInt32(json["code"].ToString());
                    if (rowIndex<2&& scanTypeName== "快件揽收"&& code==10)
                    {
                        roadInfo.lanshouTime = scanTime;
                    }
                    if(status== "已签收"&& roadInfo.donePackTime=="")
                    {
                        roadInfo.donePackTime = scanTime;
                    }
                    if(scanNetworkName == siteName)
                    {
                        if(scanTypeName == "到件扫描"|| scanTypeName == "卸车到件")
                        {
                            roadInfo.arriveSiteTime = scanTime;
                        }
                        if (status == "派件中"&& scanTypeName== "出仓扫描"&& roadInfo.assignPackTime=="")
                        {
                            roadInfo.assignPackTime = scanTime;
                        }
                        if(status == "派件中" && scanTypeName == "入库扫描" && roadInfo.yizhanRecTime == ""&& waybillTrackingContent.Contains("您的快件已存放至"))
                        {
                            roadInfo.yizhanRecTime = scanTime;
                            if(roadInfo.donePackTime!=""&&Convert.ToDateTime(roadInfo.donePackTime)<Convert.ToDateTime(scanTime))
                            {
                                roadInfo.strErrorMsg = "签收后又入驿站";
                                isDelay = true;
                                break;
                            }
                        }
                        if (status == "派件中" && scanTypeName == "入库扫描" && !waybillTrackingContent.Contains("您的快件已存放至"))
                        {
                            isPacelInYizhan=true;
                        }
                    }

                    rowIndex++;

                }
                isDelay = (isAssignDelay(roadInfo) || isYizhanDelay(roadInfo) || isLostParcel(roadInfo));
                

            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isParcelDelay ex:" + ex.ToString()+" rowIndex="+ rowIndex.ToString());
            }
            return isDelay;
        }

        /// <summary>
        /// 派送超时判断
        /// </summary>
        /// <param name="roadInfo"></param>
        /// <returns></returns>
        private bool isAssignDelay(RoadInfo roadInfo)
        {
            bool res = false;
            try
            {
                if(roadInfo.arriveSiteTime!=""&& roadInfo.assignPackTime!="")
                {
                    DateTime dtArrival = Convert.ToDateTime(roadInfo.arriveSiteTime);
                    DateTime dtAssign = Convert.ToDateTime(roadInfo.assignPackTime);
                    TimeSpan ts = dtAssign - dtArrival;
                    if(dtArrival.Hour<12&& dtAssign.ToShortDateString()!= dtArrival.ToShortDateString())
                    {
                        res = true;
                        roadInfo.strErrorMsg = "派送超时";
                    }
                }
                
            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isAssignDelay ex:" + ex.ToString());
            }
            return res;
        }

        private bool isYizhanDelay(RoadInfo roadInfo)
        {
            bool res = false;
            try
            {
                if (roadInfo.arriveSiteTime != "" && roadInfo.yizhanRecTime != "")
                {
                    DateTime dtArrival = Convert.ToDateTime(roadInfo.arriveSiteTime);
                    DateTime dtYizhan = Convert.ToDateTime(roadInfo.yizhanRecTime);
                    TimeSpan ts = dtYizhan - dtArrival;
                    if (dtArrival.Hour < 12 && dtYizhan.ToShortDateString() != dtArrival.ToShortDateString())
                    {
                        res = true;
                        roadInfo.strErrorMsg = "驿站超时";
                    }
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isYizhanDelay ex:" + ex.ToString());
            }
            return res;
        }

        private bool isLostParcel(RoadInfo roadInfo)
        {
            bool res = false;
            try
            {
                if(roadInfo.lastScanStatus!= "已签收"&& roadInfo.yizhanRecTime=="")
                {
                    DateTime dtLastScanTime = Convert.ToDateTime(roadInfo.lastSacnTime);
                    TimeSpan ts = DateTime.Now - dtLastScanTime;
                    if(ts.TotalHours>48)
                    {
                        roadInfo.strErrorMsg = "遗失";
                        res = true;
                    }
                }
            }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("isLostParcel ex:" + ex.ToString());
            }
            return res;
        }



        public JObject packageArea(JToken adCode,JToken cnName)
        {
            JObject resJObj = new JObject();
            bool res = false;
            try
            {
                bool isOther = false;
                try
                {
                    resJObj["id"] = Convert.ToInt32(adCode);
                }
                catch(Exception ex)
                {
                    isOther = true;
                }
                if(!isOther)
                {
                    resJObj["adCode"] = adCode.ToString();
                    resJObj["cnName"] = cnName;
                    resJObj["code"] = adCode.ToString();
                    resJObj["id"] = Convert.ToInt32(adCode);
                }
                else
                {
                    resJObj["adCode"] = "441902";
                    resJObj["cnName"] = "其它区";
                    resJObj["code"] = "441902";
                    resJObj["id"] = 820426;
                }
                resJObj["enName"] = "";
                resJObj["name"] = null;
                resJObj["sort"] = 0;
                resJObj["levelType"] = null;
                resJObj["nativeName"] = resJObj["cnName"];
                resJObj["noDistrictFlag"] = 2;
                resJObj["regionalId"] = 18;
                resJObj["regionalDesc"] = null;



            }
            catch (Exception ex)
            {
                //System.Windows.Forms.MessageBox.Show("packageArea ex:" + ex.ToString());
            }
            return resJObj;
        }

        private ArrayList getReturnPartRoadMap(ArrayList arListRoadMap)
        {
            ArrayList arListPart = new ArrayList();
            try
            {
                int subIndex = 0;
                for(int i=0;i< arListRoadMap.Count;i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if(roadBean.scanTypeName.Contains("退件")&& roadBean.scanNetworkName!=StoParams.Instance.register_site)
                    {
                        subIndex = i;
                    }
                }
                if(subIndex>0)
                {
                   for(int i= subIndex;i < arListRoadMap.Count; i++)
                   {
                        RoadBean roadBean = (RoadBean)arListRoadMap[i];
                        arListPart.Add(roadBean);
                    }
                   
                }

            }
            catch(Exception ex)
            {

            }
            return arListPart;

        }


        public bool isReturnCenterDelay(ArrayList arListRoadMap,ResultBean resultBean)
        {
            bool res = false;
            try
            {
                string returnSiteNam = "";
                string returnSiteDepTime = "";
                string nextStopName = "";
                string nextStopArrivalTime = "";

                for (int i=0;i< arListRoadMap.Count;i++)
                {
                    RoadBean roadBean = (RoadBean)arListRoadMap[i];
                    if(roadBean.scanTypeName.Contains("退件")&& roadBean.scanNetworkName.Contains("网点")&& roadBean.scanNetworkName!=StoParams.Instance.register_site)
                    {
                        returnSiteNam = roadBean.scanNetworkName;
                        continue;
                    }
                    if(roadBean.scanNetworkName== returnSiteNam && roadBean.scanTypeName.Contains("发件"))
                    {
                        if(returnSiteDepTime=="")
                        {
                            returnSiteDepTime = roadBean.scanTime;
                            if (roadBean.nextStopName != "")
                            {
                                nextStopName = roadBean.nextStopName;
                            }
                        }
                        
                        continue;
                    }
                    if(roadBean.scanNetworkName == nextStopName&& nextStopName.Length>1&& roadBean.scanTypeName.Contains("到件"))
                    {
                        if(nextStopArrivalTime=="")
                        {
                            nextStopArrivalTime = roadBean.scanTime;
                            break;
                        }
                        
                    }
                }

                if(nextStopName.Contains("转运")|| nextStopName.Contains("分拨"))
                {
                    TimeSpan ts = Convert.ToDateTime(nextStopArrivalTime) - Convert.ToDateTime(returnSiteDepTime);
                    if(ts.TotalHours>36)
                    {
                        res = true;
                        resultBean.dutySite = returnSiteNam;
                        resultBean.errorType = "退回延误";
                        resultBean.errorMsg= "退回延误";
                        double delayDays = Math.Floor((double)ts.TotalDays);
                        int iDay = (int)delayDays;
                        resultBean.delayDays = (iDay-1).ToString();
                        if(resultBean.delayDays=="0")
                        {
                            resultBean.delayDays = "1";
                        }


                    }
                }
            }
            catch(Exception ex)
            {

            }
            return res;

        }

    }
}
